Skip to content

Commit df7435d

Browse files
committed
Consistently return errorType when detecting circularities
1 parent 32b618c commit df7435d

26 files changed

Lines changed: 119 additions & 148 deletions

src/compiler/checker.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7315,7 +7315,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
73157315

73167316
if (propertySymbol.flags & SymbolFlags.Accessor) {
73177317
const writeType = getWriteTypeOfSymbol(propertySymbol);
7318-
if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
7318+
if (propertyType !== writeType) {
73197319
const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!;
73207320
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
73217321
typeElements.push(
@@ -11769,7 +11769,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1176911769
else if (getter && noImplicitAny) {
1177011770
error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol));
1177111771
}
11772-
type = anyType;
11772+
type = errorType;
1177311773
}
1177411774
links.type = type;
1177511775
}
@@ -11790,7 +11790,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1179011790
if (getAnnotatedAccessorTypeNode(setter)) {
1179111791
error(setter, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
1179211792
}
11793-
writeType = anyType;
11793+
writeType = errorType;
1179411794
}
1179511795
// Absent an explicit setter type annotation we use the read type of the accessor.
1179611796
links.writeType = writeType || getTypeOfAccessors(symbol);
@@ -11886,8 +11886,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1188611886
: errorType;
1188711887

1188811888
if (!popTypeResolution()) {
11889-
reportCircularityError(exportSymbol ?? symbol);
11890-
return links.type = errorType;
11889+
return links.type = reportCircularityError(exportSymbol ?? symbol);
1189111890
}
1189211891
}
1189311892
return links.type;
@@ -11925,7 +11924,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1192511924
// Circularities could also result from parameters in function expressions that end up
1192611925
// having themselves as contextual types following type argument inference. In those cases
1192711926
// we have already reported an implicit any error so we don't report anything here.
11928-
return anyType;
11927+
return errorType;
1192911928
}
1193011929

1193111930
function getTypeOfSymbolWithDeferredType(symbol: Symbol) {
@@ -15328,7 +15327,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1532815327
}
1532915328
}
1533015329
}
15331-
type = anyType;
15330+
type = errorType;
1533215331
}
1533315332
signature.resolvedReturnType = type;
1533415333
}

tests/baselines/reference/assignmentCompatWithObjectMembers.types

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ module ObjectTypes {
189189
>b : { foo: any; }
190190

191191
var a2 = { foo: a2 };
192-
>a2 : any
192+
>a2 : error
193193
>{ foo: a2 } : { foo: any; }
194-
>foo : any
195-
>a2 : any
194+
>foo : error
195+
>a2 : error
196196

197197
var b2 = { foo: b2 };
198-
>b2 : any
198+
>b2 : error
199199
>{ foo: b2 } : { foo: any; }
200-
>foo : any
201-
>b2 : any
200+
>foo : error
201+
>b2 : error
202202

203203
s = t;
204204
>s = t : T
@@ -216,9 +216,9 @@ module ObjectTypes {
216216
>s2 : S2
217217

218218
s = a2;
219-
>s = a2 : any
219+
>s = a2 : error
220220
>s : S
221-
>a2 : any
221+
>a2 : error
222222

223223
s2 = t2;
224224
>s2 = t2 : T2
@@ -241,9 +241,9 @@ module ObjectTypes {
241241
>b : { foo: any; }
242242

243243
s2 = a2;
244-
>s2 = a2 : any
244+
>s2 = a2 : error
245245
>s2 : S2
246-
>a2 : any
246+
>a2 : error
247247

248248
a = b;
249249
>a = b : { foo: any; }
@@ -266,33 +266,33 @@ module ObjectTypes {
266266
>s2 : S2
267267

268268
a = a2;
269-
>a = a2 : any
269+
>a = a2 : error
270270
>a : { foo: any; }
271-
>a2 : any
271+
>a2 : error
272272

273273
a2 = b2;
274-
>a2 = b2 : any
275-
>a2 : any
276-
>b2 : any
274+
>a2 = b2 : error
275+
>a2 : error
276+
>b2 : error
277277

278278
b2 = a2;
279-
>b2 = a2 : any
280-
>b2 : any
281-
>a2 : any
279+
>b2 = a2 : error
280+
>b2 : error
281+
>a2 : error
282282

283283
a2 = b;
284284
>a2 = b : { foo: any; }
285-
>a2 : any
285+
>a2 : error
286286
>b : { foo: any; }
287287

288288
a2 = t2;
289289
>a2 = t2 : T2
290-
>a2 : any
290+
>a2 : error
291291
>t2 : T2
292292

293293
a2 = t;
294294
>a2 = t : T
295-
>a2 : any
295+
>a2 : error
296296
>t : T
297297

298298
}

tests/baselines/reference/binderUninitializedModuleExportsAssignment.types

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
=== loop.js ===
44
var loop1 = loop2;
5-
>loop1 : any
6-
>loop2 : any
5+
>loop1 : error
6+
>loop2 : error
77

88
var loop2 = loop1;
9-
>loop2 : any
10-
>loop1 : any
9+
>loop2 : error
10+
>loop1 : error
1111

1212
module.exports = loop2;
13-
>module.exports = loop2 : any
14-
>module.exports : any
13+
>module.exports = loop2 : error
14+
>module.exports : error
1515
>module : { exports: any; }
1616
>exports : any
17-
>loop2 : any
17+
>loop2 : error
1818

tests/baselines/reference/circularMultipleAssignmentDeclaration.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
=== circularMultipleAssignmentDeclaration.js ===
44
ns.next = ns.next || { shared: {} };
55
>ns.next = ns.next || { shared: {} } : any
6-
>ns.next : any
6+
>ns.next : error
77
>ns : typeof ns
88
>next : any
99
>ns.next || { shared: {} } : any
10-
>ns.next : any
10+
>ns.next : error
1111
>ns : typeof ns
1212
>next : any
1313
>{ shared: {} } : { shared: {}; }
@@ -16,7 +16,7 @@ ns.next = ns.next || { shared: {} };
1616

1717
ns.next.shared.mymethod = {};
1818
>ns.next.shared.mymethod = {} : {}
19-
>ns.next.shared.mymethod : any
19+
>ns.next.shared.mymethod : error
2020
>ns.next.shared : any
2121
>ns.next : any
2222
>ns : typeof ns

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } };
5454
>{ b5: { b52 } } : { b5: { b52: any; }; }
5555
>b5 : { b52: any; }
5656
>{ b52 } : { b52: any; }
57-
>b52 : any
57+
>b52 : error
5858

5959
// V is an object assignment pattern and, for each assignment property P in V,
6060
// P specifies a numeric property name and S has a numeric index signature

tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } };
5454
>{ b5: { b52 } } : { b5: { b52: any; }; }
5555
>b5 : { b52: any; }
5656
>{ b52 } : { b52: any; }
57-
>b52 : any
57+
>b52 : error
5858

5959
// V is an object assignment pattern and, for each assignment property P in V,
6060
// P specifies a numeric property name and S has a numeric index signature

tests/baselines/reference/exportAssignmentCircularModules.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module Foo {
88
>Foo : typeof Foo
99

1010
export var x = foo0.x;
11-
>x : any
12-
>foo0.x : any
11+
>x : error
12+
>foo0.x : error
1313
>foo0 : typeof foo0
1414
>x : any
1515
}
@@ -24,8 +24,8 @@ module Foo {
2424
>Foo : typeof Foo
2525

2626
export var x = foo1.x;
27-
>x : any
28-
>foo1.x : any
27+
>x : error
28+
>foo1.x : error
2929
>foo1 : typeof foo1
3030
>x : any
3131
}
@@ -40,8 +40,8 @@ module Foo {
4040
>Foo : typeof Foo
4141

4242
export var x = foo2.x;
43-
>x : any
44-
>foo2.x : any
43+
>x : error
44+
>foo2.x : error
4545
>foo2 : typeof foo2
4646
>x : any
4747
}

tests/baselines/reference/jsDeclarationsExportDoubleAssignmentInClosure.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function foo() {
1111
>module : { exports: { (o: any): any; methods: () => void; }; }
1212
>exports : { (o: any): any; methods: () => void; }
1313
>exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
14-
>exports : any
14+
>exports : error
1515
>function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
1616
>o : any
1717

@@ -39,7 +39,7 @@ function foo() {
3939
}
4040
exports.methods = m;
4141
>exports.methods = m : () => void
42-
>exports.methods : any
42+
>exports.methods : error
4343
>exports : any
4444
>methods : any
4545
>m : () => void

tests/baselines/reference/moduleExportAssignment4.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=== async.js ===
44
exports.default = { m: 1, a: 1 }
55
>exports.default = { m: 1, a: 1 } : { m: number; a: number; }
6-
>exports.default : any
6+
>exports.default : error
77
>exports : any
88
>default : any
99
>{ m: 1, a: 1 } : { m: number; a: number; }
@@ -17,7 +17,7 @@ module.exports = exports['default'];
1717
>module.exports : error
1818
>module : { exports: any; }
1919
>exports : any
20-
>exports['default'] : any
21-
>exports : any
20+
>exports['default'] : error
21+
>exports : error
2222
>'default' : "default"
2323

tests/baselines/reference/noUsedBeforeDefinedErrorInTypeContext.types

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ interface IThing<T> {
99
}
1010

1111
var foo = {
12-
>foo : any
12+
>foo : error
1313
>{ one: {} as IThing<typeof foo>,} : { one: IThing<any>; }
1414

1515
one: {} as IThing<typeof foo>,
1616
>one : IThing<any>
1717
>{} as IThing<typeof foo> : IThing<any>
1818
>{} : {}
19-
>foo : any
19+
>foo : error
2020
}
2121

2222
let baz = {
@@ -27,28 +27,28 @@ let baz = {
2727
>two : IThing<any>
2828
>{} as IThing<typeof bar> : IThing<any>
2929
>{} : {}
30-
>bar : any
30+
>bar : error
3131
}
3232

3333
let bar = {
34-
>bar : any
34+
>bar : error
3535
>{ three: {} as IThing<typeof bar>,} : { three: IThing<any>; }
3636

3737
three: {} as IThing<typeof bar>,
3838
>three : IThing<any>
3939
>{} as IThing<typeof bar> : IThing<any>
4040
>{} : {}
41-
>bar : any
41+
>bar : error
4242
}
4343

4444
const qwe = {
45-
>qwe : any
45+
>qwe : error
4646
>{ four: {} as IThing<typeof qwe>,} : { four: IThing<any>; }
4747

4848
four: {} as IThing<typeof qwe>,
4949
>four : IThing<any>
5050
>{} as IThing<typeof qwe> : IThing<any>
5151
>{} : {}
52-
>qwe : any
52+
>qwe : error
5353
}
5454

0 commit comments

Comments
 (0)