Skip to content

Partially disable inference recursion tracking changes #40256

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

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 7 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18287,12 +18287,12 @@ namespace ts {
// identity is some object that is common to instantiations of the type with the same origin.
function getRecursionIdentity(type: Type): object | undefined {
if (type.flags & TypeFlags.Object && !isObjectOrArrayLiteralType(type)) {
if (getObjectFlags(type) && ObjectFlags.Reference && (type as TypeReference).node) {
// Deferred type references are tracked through their associated AST node. This gives us finer
// granularity than using their associated target because each manifest type reference has a
// unique AST node.
return (type as TypeReference).node;
}
// if (getObjectFlags(type) && ObjectFlags.Reference && (type as TypeReference).node) {
// // Deferred type references are tracked through their associated AST node. This gives us finer
// // granularity than using their associated target because each manifest type reference has a
// // unique AST node.
// return (type as TypeReference).node;
// }
if (type.symbol && !(getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol.flags & SymbolFlags.Class)) {
// We track all object types that have an associated symbol (representing the origin of the type), but
// exclude the static side of classes from this check since it shares its symbol with the instance side.
Expand Down Expand Up @@ -19603,7 +19603,7 @@ namespace ts {
const sourceIdentity = getRecursionIdentity(source);
const targetIdentity = getRecursionIdentity(target);
if (sourceIdentity && contains(sourceStack, sourceIdentity)) expandingFlags |= ExpandingFlags.Source;
if (targetIdentity && contains(targetStack, targetIdentity)) expandingFlags |= ExpandingFlags.Target;
if (targetIdentity && contains(targetStack, targetIdentity)) expandingFlags |= ExpandingFlags.Both;
if (expandingFlags !== ExpandingFlags.Both) {
if (sourceIdentity) (sourceStack || (sourceStack = [])).push(sourceIdentity);
if (targetIdentity) (targetStack || (targetStack = [])).push(targetIdentity);
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/promiseTypeInference.types
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ declare function convert(s: string): IPromise<number>;
>s : string

var $$x = load("something").then(s => convert(s));
>$$x : CPromise<number>
>load("something").then(s => convert(s)) : CPromise<number>
>$$x : CPromise<unknown>
>load("something").then(s => convert(s)) : CPromise<unknown>
>load("something").then : <U>(success?: (value: string) => CPromise<U>) => CPromise<U>
>load("something") : CPromise<string>
>load : (name: string) => CPromise<string>
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/recursiveConditionalTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ unbox(b1); // string
>b1 : Box<Box<Box<Box<Box<Box<string>>>>>>

unbox(b2); // string
>unbox(b2) : string
>unbox(b2) : T6
>unbox : <T>(box: RecBox<T>) => T
>b2 : T6

Expand All @@ -200,7 +200,7 @@ unbox(b3); // InfBox<string>
>b3 : InfBox<string>

unbox({ value: { value: { value: { value: { value: { value: 5 }}}}}}); // number
>unbox({ value: { value: { value: { value: { value: { value: 5 }}}}}}) : number
>unbox({ value: { value: { value: { value: { value: { value: 5 }}}}}}) : { value: { value: { value: { value: { value: number; }; }; }; }; } | { value: { value: { value: { value: { value: { value: number; }; }; }; }; }; }
>unbox : <T>(box: RecBox<T>) => T
>{ value: { value: { value: { value: { value: { value: 5 }}}}}} : { value: { value: { value: { value: { value: { value: number; }; }; }; }; }; }
>value : { value: { value: { value: { value: { value: number; }; }; }; }; }
Expand All @@ -222,15 +222,15 @@ unbox(b4); // { value: { value: typeof b4 }}
>b4 : { value: { value: { value: any; }; }; }

unbox({ value: { value: { get value() { return this; } }}}); // { readonly value: ... }
>unbox({ value: { value: { get value() { return this; } }}}) : { readonly value: { readonly value: any; }; }
>unbox({ value: { value: { get value() { return this; } }}}) : { value: { readonly value: { readonly value: any; }; }; }
>unbox : <T>(box: RecBox<T>) => T
>{ value: { value: { get value() { return this; } }}} : { value: { value: { readonly value: { readonly value: any; }; }; }; }
>value : { value: { readonly value: { readonly value: any; }; }; }
>{ value: { get value() { return this; } }} : { value: { readonly value: { readonly value: any; }; }; }
>value : { readonly value: { readonly value: any; }; }
>{ get value() { return this; } } : { readonly value: { readonly value: any; }; }
>value : { readonly value: any; }
>this : { readonly value: any; } | { readonly value: { readonly value: any; }; } | Box<RecBox<{ readonly value: { readonly value: any; }; }>>
>this : { readonly value: any; } | { readonly value: { readonly value: any; }; } | { value: { readonly value: { readonly value: any; }; }; } | Box<RecBox<{ value: { readonly value: { readonly value: any; }; }; }>>

// Inference from nested instantiations of same generic types

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type t1 = Box<string | Box<number | boolean>>
>t1 : t1

type t2 = InferRecursive<t1>
>t2 : string | number | boolean
>t2 : "never!"

type t3 = InferRecursive<Box<string | Box<number | boolean>>> // write t1 explicitly
>t3 : string | number | boolean
Expand Down