Skip to content

Commit c3c40e2

Browse files
authored
Merge branch 'main' into fix/slice-bounds-panic-issue-1691
2 parents c359bdb + 0442f87 commit c3c40e2

15 files changed

+686
-70
lines changed

.github/actions/setup-go/action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ runs:
3939
4040
- if: ${{ inputs.create != 'true' }}
4141
name: Restore Go modules
42-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
42+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
4343
with:
4444
key: ${{ steps.cache-info.outputs.modules-key }}
4545
path: |
4646
~/go/pkg/mod
4747
4848
- if: ${{ inputs.create != 'true' }}
4949
name: Restore Go build cache
50-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
50+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
5151
with:
5252
key: unused-key-${{ github.run_id }}
5353
restore-keys: ${{ steps.cache-info.outputs.build-key }}-
@@ -58,7 +58,7 @@ runs:
5858
5959
- if: ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
6060
name: Restore golangci-lint cache
61-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
61+
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
6262
with:
6363
key: unused-key-${{ github.run_id }}
6464
restore-keys: ${{ steps.cache-info.outputs.lint-key }}-
@@ -114,15 +114,15 @@ runs:
114114

115115
- if: ${{ inputs.create == 'true' }}
116116
name: Save Go modules
117-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
117+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
118118
with:
119119
key: ${{ steps.cache-info.outputs.modules-key }}
120120
path: |
121121
~/go/pkg/mod
122122
123123
- if: ${{ inputs.create == 'true' }}
124124
name: Save Go build cache
125-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
125+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
126126
with:
127127
key: ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
128128
path: |
@@ -132,7 +132,7 @@ runs:
132132
133133
- if: ${{ inputs.create == 'true' }}
134134
name: Save golangci-lint cache
135-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
135+
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
136136
with:
137137
key: ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
138138
path: ${{ env.GOLANGCI_LINT_CACHE }}

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
# Initializes the CodeQL tools for scanning.
5050
- name: Initialize CodeQL
51-
uses: github/codeql-action/init@192325c86100d080feab897ff886c34abd4c83a3 # v3.29.5
51+
uses: github/codeql-action/init@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
5252
with:
5353
config-file: ./.github/codeql/codeql-configuration.yml
5454
# Override language selection by uncommenting this and choosing your languages
@@ -58,7 +58,7 @@ jobs:
5858
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5959
# If this step fails, then you should remove it and run the build manually (see below).
6060
- name: Autobuild
61-
uses: github/codeql-action/autobuild@192325c86100d080feab897ff886c34abd4c83a3 # v3.29.5
61+
uses: github/codeql-action/autobuild@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5
6262

6363
# ℹ️ Command-line programs to run using the OS shell.
6464
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,4 +72,4 @@ jobs:
7272
# make release
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@192325c86100d080feab897ff886c34abd4c83a3 # v3.29.5
75+
uses: github/codeql-action/analyze@3599b3baa15b485a2e49ef411a7a4bb2452e7f93 # v3.29.5

internal/binder/binder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,12 +2243,12 @@ func (b *Binder) bindBinaryExpressionFlow(node *ast.Node) {
22432243
b.bind(expr.Left)
22442244
b.bind(expr.Type)
22452245
if operator == ast.KindCommaToken {
2246-
b.maybeBindExpressionFlowIfCall(node)
2246+
b.maybeBindExpressionFlowIfCall(expr.Left)
22472247
}
22482248
b.bind(expr.OperatorToken)
22492249
b.bind(expr.Right)
22502250
if operator == ast.KindCommaToken {
2251-
b.maybeBindExpressionFlowIfCall(node)
2251+
b.maybeBindExpressionFlowIfCall(expr.Right)
22522252
}
22532253
if ast.IsAssignmentOperator(operator) && !ast.IsAssignmentTarget(node) {
22542254
b.bindAssignmentTargetFlow(expr.Left)

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29417,7 +29417,7 @@ func (c *Checker) discriminateContextualTypeByObjectMembers(node *ast.Node, cont
2941729417

2941829418
func (c *Checker) getMatchingUnionConstituentForObjectLiteral(unionType *Type, node *ast.Node) *Type {
2941929419
keyPropertyName := c.getKeyPropertyName(unionType)
29420-
if keyPropertyName == "" {
29420+
if keyPropertyName != "" {
2942129421
propNode := core.Find(node.AsObjectLiteralExpression().Properties.Nodes, func(p *ast.Node) bool {
2942229422
return p.Symbol() != nil && ast.IsPropertyAssignment(p) && p.Symbol().Name == keyPropertyName && c.isPossiblyDiscriminantValue(p.Initializer())
2942329423
})

internal/checker/relater.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,24 +1167,22 @@ func (c *Checker) mapTypesByKeyProperty(types []*Type, keyPropertyName string) m
11671167
for _, t := range types {
11681168
if t.flags&(TypeFlagsObject|TypeFlagsIntersection|TypeFlagsInstantiableNonPrimitive) != 0 {
11691169
discriminant := c.getTypeOfPropertyOfType(t, keyPropertyName)
1170-
if discriminant != nil {
1171-
if !isLiteralType(discriminant) {
1172-
return nil
1173-
}
1174-
duplicate := false
1175-
for _, d := range discriminant.Distributed() {
1176-
key := c.getRegularTypeOfLiteralType(d)
1177-
if existing := typesByKey[key]; existing == nil {
1178-
typesByKey[key] = t
1179-
} else if existing != c.unknownType {
1180-
typesByKey[key] = c.unknownType
1181-
duplicate = true
1182-
}
1183-
}
1184-
if !duplicate {
1185-
count++
1170+
if discriminant == nil || !isLiteralType(discriminant) {
1171+
return nil
1172+
}
1173+
duplicate := false
1174+
for _, d := range discriminant.Distributed() {
1175+
key := c.getRegularTypeOfLiteralType(d)
1176+
if existing := typesByKey[key]; existing == nil {
1177+
typesByKey[key] = t
1178+
} else if existing != c.unknownType {
1179+
typesByKey[key] = c.unknownType
1180+
duplicate = true
11861181
}
11871182
}
1183+
if !duplicate {
1184+
count++
1185+
}
11881186
}
11891187
}
11901188
if count >= 10 && count*2 >= len(types) {
@@ -4156,13 +4154,10 @@ func (r *Relater) propertiesRelatedTo(source *Type, target *Type, reportErrors b
41564154
if isObjectLiteralType(target) {
41574155
for _, sourceProp := range excludeProperties(r.c.getPropertiesOfType(source), excludedProperties) {
41584156
if r.c.getPropertyOfObjectType(target, sourceProp.Name) == nil {
4159-
sourceType := r.c.getTypeOfSymbol(sourceProp)
4160-
if sourceType.flags&TypeFlagsUndefined == 0 {
4161-
if reportErrors {
4162-
r.reportError(diagnostics.Property_0_does_not_exist_on_type_1, r.c.symbolToString(sourceProp), r.c.TypeToString(target))
4163-
}
4164-
return TernaryFalse
4157+
if reportErrors {
4158+
r.reportError(diagnostics.Property_0_does_not_exist_on_type_1, r.c.symbolToString(sourceProp), r.c.TypeToString(target))
41654159
}
4160+
return TernaryFalse
41664161
}
41674162
}
41684163
}

internal/ls/findallreferences.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
616616

617617
if node.Kind == ast.KindSourceFile {
618618
resolvedRef := getReferenceAtPosition(node.AsSourceFile(), position, program)
619-
if resolvedRef.file == nil {
619+
if resolvedRef == nil || resolvedRef.file == nil {
620620
return nil
621621
}
622622

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//// [tests/cases/compiler/freshObjectLiteralSubtype.ts] ////
2+
3+
=== freshObjectLiteralSubtype.ts ===
4+
function f1() {
5+
>f1 : Symbol(f1, Decl(freshObjectLiteralSubtype.ts, 0, 0))
6+
7+
if (!!true) {
8+
return { valid: true }
9+
>valid : Symbol(valid, Decl(freshObjectLiteralSubtype.ts, 2, 16))
10+
}
11+
return f2()
12+
>f2 : Symbol(f2, Decl(freshObjectLiteralSubtype.ts, 7, 13))
13+
}
14+
15+
declare const f2: () => { valid: boolean, msg?: undefined }
16+
>f2 : Symbol(f2, Decl(freshObjectLiteralSubtype.ts, 7, 13))
17+
>valid : Symbol(valid, Decl(freshObjectLiteralSubtype.ts, 7, 25))
18+
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 7, 41))
19+
20+
f1().msg
21+
>f1().msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 7, 41))
22+
>f1 : Symbol(f1, Decl(freshObjectLiteralSubtype.ts, 0, 0))
23+
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 7, 41))
24+
25+
// Repro from https://github.com/microsoft/typescript-go/issues/1742
26+
27+
function validate() {
28+
>validate : Symbol(validate, Decl(freshObjectLiteralSubtype.ts, 9, 8))
29+
30+
if(Math.random() > 0.5) {
31+
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
32+
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.float16.d.ts, --, --))
33+
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
34+
35+
return utilValidate();
36+
>utilValidate : Symbol(utilValidate, Decl(freshObjectLiteralSubtype.ts, 18, 2))
37+
}
38+
return { valid: true };
39+
>valid : Symbol(valid, Decl(freshObjectLiteralSubtype.ts, 17, 12))
40+
41+
};
42+
43+
44+
declare function utilValidate(): {
45+
>utilValidate : Symbol(utilValidate, Decl(freshObjectLiteralSubtype.ts, 18, 2))
46+
47+
valid: boolean;
48+
>valid : Symbol(valid, Decl(freshObjectLiteralSubtype.ts, 21, 34))
49+
50+
msg?: undefined;
51+
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 22, 19))
52+
53+
} | {
54+
valid: boolean;
55+
>valid : Symbol(valid, Decl(freshObjectLiteralSubtype.ts, 24, 5))
56+
57+
msg: string;
58+
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 25, 19))
59+
}
60+
61+
validate().msg; // Error in TSGO
62+
>validate().msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 22, 19), Decl(freshObjectLiteralSubtype.ts, 25, 19))
63+
>validate : Symbol(validate, Decl(freshObjectLiteralSubtype.ts, 9, 8))
64+
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 22, 19), Decl(freshObjectLiteralSubtype.ts, 25, 19))
65+
66+
// https://github.com/microsoft/typescript-go/issues/1761
67+
68+
function normalise_trace_logs([log]: any[]) {
69+
>normalise_trace_logs : Symbol(normalise_trace_logs, Decl(freshObjectLiteralSubtype.ts, 29, 15))
70+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
71+
72+
let normalised = [];
73+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
74+
75+
if (typeof log === "string" && log.includes("%c")) {
76+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
77+
>log.includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
78+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
79+
>includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
80+
81+
normalised.push({ log, highlighted: log.includes("foo") });
82+
>normalised.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
83+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
84+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
85+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 36, 25))
86+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 36, 30))
87+
>log.includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
88+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
89+
>includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
90+
91+
} else {
92+
normalised.push({ log });
93+
>normalised.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
94+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
95+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
96+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 38, 25))
97+
}
98+
return normalised;
99+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
100+
}
101+
102+
function equal<T>(_actual: T, _expected: T): void {}
103+
>equal : Symbol(equal, Decl(freshObjectLiteralSubtype.ts, 41, 1))
104+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
105+
>_actual : Symbol(_actual, Decl(freshObjectLiteralSubtype.ts, 43, 18))
106+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
107+
>_expected : Symbol(_expected, Decl(freshObjectLiteralSubtype.ts, 43, 29))
108+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
109+
110+
equal(normalise_trace_logs([]), [
111+
>equal : Symbol(equal, Decl(freshObjectLiteralSubtype.ts, 41, 1))
112+
>normalise_trace_logs : Symbol(normalise_trace_logs, Decl(freshObjectLiteralSubtype.ts, 29, 15))
113+
114+
{ log: 'effect' },
115+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 46, 5))
116+
117+
{ log: '$derived', highlighted: true },
118+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 47, 5))
119+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 47, 22))
120+
121+
{ log: 'double', highlighted: false },
122+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 48, 5))
123+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 48, 20))
124+
125+
{ log: 4 },
126+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 49, 5))
127+
128+
]);
129+

0 commit comments

Comments
 (0)