Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently return errorType when detecting circularities #56429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7315,7 +7315,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

if (propertySymbol.flags & SymbolFlags.Accessor) {
const writeType = getWriteTypeOfSymbol(propertySymbol);
if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
if (propertyType !== writeType) {
const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!;
const getterSignature = getSignatureFromDeclaration(getterDeclaration);
typeElements.push(
Expand Down Expand Up @@ -11769,7 +11769,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else if (getter && noImplicitAny) {
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));
}
type = anyType;
type = errorType;
}
links.type = type;
}
Expand All @@ -11790,7 +11790,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (getAnnotatedAccessorTypeNode(setter)) {
error(setter, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
}
writeType = anyType;
writeType = errorType;
}
// Absent an explicit setter type annotation we use the read type of the accessor.
links.writeType = writeType || getTypeOfAccessors(symbol);
Expand Down Expand Up @@ -11886,8 +11886,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
: errorType;

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

function getTypeOfSymbolWithDeferredType(symbol: Symbol) {
Expand Down Expand Up @@ -15328,7 +15327,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
}
type = anyType;
type = errorType;
}
signature.resolvedReturnType = type;
}
Expand Down
42 changes: 21 additions & 21 deletions tests/baselines/reference/assignmentCompatWithObjectMembers.types
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ module ObjectTypes {
>b : { foo: any; }

var a2 = { foo: a2 };
>a2 : any
>a2 : error
jakebailey marked this conversation as resolved.
Show resolved Hide resolved
>{ foo: a2 } : { foo: any; }
>foo : any
>a2 : any
>foo : error
>a2 : error

var b2 = { foo: b2 };
>b2 : any
>b2 : error
>{ foo: b2 } : { foo: any; }
>foo : any
>b2 : any
>foo : error
>b2 : error

s = t;
>s = t : T
Expand All @@ -216,9 +216,9 @@ module ObjectTypes {
>s2 : S2

s = a2;
>s = a2 : any
>s = a2 : error
>s : S
>a2 : any
>a2 : error

s2 = t2;
>s2 = t2 : T2
Expand All @@ -241,9 +241,9 @@ module ObjectTypes {
>b : { foo: any; }

s2 = a2;
>s2 = a2 : any
>s2 = a2 : error
>s2 : S2
>a2 : any
>a2 : error

a = b;
>a = b : { foo: any; }
Expand All @@ -266,33 +266,33 @@ module ObjectTypes {
>s2 : S2

a = a2;
>a = a2 : any
>a = a2 : error
>a : { foo: any; }
>a2 : any
>a2 : error

a2 = b2;
>a2 = b2 : any
>a2 : any
>b2 : any
>a2 = b2 : error
>a2 : error
>b2 : error

b2 = a2;
>b2 = a2 : any
>b2 : any
>a2 : any
>b2 = a2 : error
>b2 : error
>a2 : error

a2 = b;
>a2 = b : { foo: any; }
>a2 : any
>a2 : error
>b : { foo: any; }

a2 = t2;
>a2 = t2 : T2
>a2 : any
>a2 : error
>t2 : T2

a2 = t;
>a2 = t : T
>a2 : any
>a2 : error
>t : T

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

=== loop.js ===
var loop1 = loop2;
>loop1 : any
>loop2 : any
>loop1 : error
>loop2 : error

var loop2 = loop1;
>loop2 : any
>loop1 : any
>loop2 : error
>loop1 : error

module.exports = loop2;
>module.exports = loop2 : any
>module.exports : any
>module.exports = loop2 : error
>module.exports : error
>module : { exports: any; }
>exports : any
>loop2 : any
>loop2 : error

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
=== circularMultipleAssignmentDeclaration.js ===
ns.next = ns.next || { shared: {} };
>ns.next = ns.next || { shared: {} } : any
>ns.next : any
>ns.next : error
>ns : typeof ns
>next : any
>ns.next || { shared: {} } : any
>ns.next : any
>ns.next : error
>ns : typeof ns
>next : any
>{ shared: {} } : { shared: {}; }
Expand All @@ -16,7 +16,7 @@ ns.next = ns.next || { shared: {} };

ns.next.shared.mymethod = {};
>ns.next.shared.mymethod = {} : {}
>ns.next.shared.mymethod : any
>ns.next.shared.mymethod : error
>ns.next.shared : any
>ns.next : any
>ns : typeof ns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } };
>{ b5: { b52 } } : { b5: { b52: any; }; }
>b5 : { b52: any; }
>{ b52 } : { b52: any; }
>b52 : any
>b52 : error

// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var {b5: { b52 } } = { b5: { b52 } };
>{ b5: { b52 } } : { b5: { b52: any; }; }
>b5 : { b52: any; }
>{ b52 } : { b52: any; }
>b52 : any
>b52 : error

// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/exportAssignmentCircularModules.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Foo {
>Foo : typeof Foo

export var x = foo0.x;
>x : any
>foo0.x : any
>x : error
>foo0.x : error
>foo0 : typeof foo0
>x : any
}
Expand All @@ -24,8 +24,8 @@ module Foo {
>Foo : typeof Foo

export var x = foo1.x;
>x : any
>foo1.x : any
>x : error
>foo1.x : error
>foo1 : typeof foo1
>x : any
}
Expand All @@ -40,8 +40,8 @@ module Foo {
>Foo : typeof Foo

export var x = foo2.x;
>x : any
>foo2.x : any
>x : error
>foo2.x : error
>foo2 : typeof foo2
>x : any
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function foo() {
>module : { exports: { (o: any): any; methods: () => void; }; }
>exports : { (o: any): any; methods: () => void; }
>exports = function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
>exports : any
>exports : error
>function (o) { return (o == null) ? create(base) : defineProperties(Object(o), descriptors); } : (o: any) => any
>o : any

Expand Down Expand Up @@ -39,7 +39,7 @@ function foo() {
}
exports.methods = m;
>exports.methods = m : () => void
>exports.methods : any
>exports.methods : error
>exports : any
>methods : any
>m : () => void
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/moduleExportAssignment4.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
=== async.js ===
exports.default = { m: 1, a: 1 }
>exports.default = { m: 1, a: 1 } : { m: number; a: number; }
>exports.default : any
>exports.default : error
>exports : any
>default : any
>{ m: 1, a: 1 } : { m: number; a: number; }
Expand All @@ -17,7 +17,7 @@ module.exports = exports['default'];
>module.exports : error
>module : { exports: any; }
>exports : any
>exports['default'] : any
>exports : any
>exports['default'] : error
>exports : error
>'default' : "default"

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface IThing<T> {
}

var foo = {
>foo : any
>foo : error
>{ one: {} as IThing<typeof foo>,} : { one: IThing<any>; }

one: {} as IThing<typeof foo>,
>one : IThing<any>
>{} as IThing<typeof foo> : IThing<any>
>{} : {}
>foo : any
>foo : error
}

let baz = {
Expand All @@ -27,28 +27,28 @@ let baz = {
>two : IThing<any>
>{} as IThing<typeof bar> : IThing<any>
>{} : {}
>bar : any
>bar : error
}

let bar = {
>bar : any
>bar : error
>{ three: {} as IThing<typeof bar>,} : { three: IThing<any>; }

three: {} as IThing<typeof bar>,
>three : IThing<any>
>{} as IThing<typeof bar> : IThing<any>
>{} : {}
>bar : any
>bar : error
}

const qwe = {
>qwe : any
>qwe : error
>{ four: {} as IThing<typeof qwe>,} : { four: IThing<any>; }

four: {} as IThing<typeof qwe>,
>four : IThing<any>
>{} as IThing<typeof qwe> : IThing<any>
>{} : {}
>qwe : any
>qwe : error
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var x2 = {
}

var x3 = {
>x3 : any
>x3 : error
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; }

a: 0,
Expand All @@ -41,11 +41,11 @@ var x3 = {
>d : () => void

x3,
>x3 : any
>x3 : error

parent: x3
>parent : any
>x3 : any
>parent : error
>x3 : error

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var x2 = {
}

var x3 = {
>x3 : any
>x3 : error
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; }

a: 0,
Expand All @@ -41,11 +41,11 @@ var x3 = {
>d : () => void

x3,
>x3 : any
>x3 : error

parent: x3
>parent : any
>x3 : any
>parent : error
>x3 : error

};

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserES5ForOfStatement18.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

=== parserES5ForOfStatement18.ts ===
for (var of of of) { }
>of : any
>of : any
>of : error
>of : error

4 changes: 2 additions & 2 deletions tests/baselines/reference/parserES5ForOfStatement19.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

=== parserES5ForOfStatement19.ts ===
for (var of in of) { }
>of : any
>of : any
>of : error
>of : error

Loading
Loading