Skip to content

Commit 071708f

Browse files
authored
Merge pull request microsoft#29959 from Microsoft/noResolvedTypeOverwrite
Never overwrite resolved types of symbols
2 parents eafff75 + ecfd408 commit 071708f

8 files changed

+20
-11
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,7 +5425,16 @@ namespace ts {
54255425

54265426
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
54275427
const links = getSymbolLinks(symbol);
5428-
return links.type || (links.type = getTypeOfVariableOrParameterOrPropertyWorker(symbol));
5428+
if (!links.type) {
5429+
const type = getTypeOfVariableOrParameterOrPropertyWorker(symbol);
5430+
// For a contextually typed parameter it is possible that a type has already
5431+
// been assigned (in assignTypeToParameterAndFixTypeParameters), and we want
5432+
// to preserve this type.
5433+
if (!links.type) {
5434+
links.type = type;
5435+
}
5436+
}
5437+
return links.type;
54295438
}
54305439

54315440
function getTypeOfVariableOrParameterOrPropertyWorker(symbol: Symbol) {
@@ -5469,7 +5478,7 @@ namespace ts {
54695478
if (symbol.flags & SymbolFlags.ValueModule) {
54705479
return getTypeOfFuncClassEnumModule(symbol);
54715480
}
5472-
return errorType;
5481+
return reportCircularityError(symbol);
54735482
}
54745483
let type: Type | undefined;
54755484
if (isInJSFile(declaration) &&
@@ -5528,7 +5537,7 @@ namespace ts {
55285537
if (symbol.flags & SymbolFlags.ValueModule) {
55295538
return getTypeOfFuncClassEnumModule(symbol);
55305539
}
5531-
type = reportCircularityError(symbol);
5540+
return reportCircularityError(symbol);
55325541
}
55335542
return type;
55345543
}

tests/baselines/reference/jsFileClassSelfReferencedProperty.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export class StackOverflowTest {
44

55
constructor () {
66
this.testStackOverflow = this.testStackOverflow.bind(this)
7-
>this.testStackOverflow = this.testStackOverflow.bind(this) : error
7+
>this.testStackOverflow = this.testStackOverflow.bind(this) : any
88
>this.testStackOverflow : any
99
>this : this
1010
>testStackOverflow : any
11-
>this.testStackOverflow.bind(this) : error
11+
>this.testStackOverflow.bind(this) : any
1212
>this.testStackOverflow.bind : any
1313
>this.testStackOverflow : any
1414
>this : this
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement18.ts ===
22
for (var of of of) { }
33
>of : any
4-
>of : error
4+
>of : any
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement19.ts ===
22
for (var of in of) { }
33
>of : any
4-
>of : error
4+
>of : any
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement18.ts ===
22
for (var of of of) { }
33
>of : any
4-
>of : error
4+
>of : any
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement19.ts ===
22
for (var of in of) { }
33
>of : any
4-
>of : error
4+
>of : any
55

tests/baselines/reference/recur1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ salt.pepper = function() {}
1515

1616
var cobalt = new cobalt.pitch();
1717
>cobalt : any
18-
>new cobalt.pitch() : error
18+
>new cobalt.pitch() : any
1919
>cobalt.pitch : any
2020
>cobalt : any
2121
>pitch : any

tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType7.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import self = require("recursiveExportAssignmentAndFindAliasedType7_moduleD");
1414

1515
var selfVar = self;
1616
>selfVar : any
17-
>self : error
17+
>self : any
1818

1919
export = selfVar;
2020
>selfVar : any

0 commit comments

Comments
 (0)