From 15f052c08fae0b414d379823a4fe2b550a888408 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 21 Oct 2026 09:03:47 -0700 Subject: [PATCH] Add tests for check order dependence These tests exercise checker results that can depend on the order in which declarations, files, and relations are checked: variance measurement cycles, relation caching under recursion and depth limits, instantiation limits, contextual re-checks, and deferred type reference cycles. Recording the current baselines makes later changes to make checking order independent show up as reviewable baseline diffs. --- ...heckReentryFromOuterTypeParameters.symbols | 81 ++++++++++++ ...lCheckReentryFromOuterTypeParameters.types | 58 +++++++++ ...erredTypeReferenceCycleRollback.errors.txt | 24 ++++ ...deferredTypeReferenceCycleRollback.symbols | 70 ++++++++++ .../deferredTypeReferenceCycleRollback.types | 34 +++++ .../instantiationLimitsCheckOrder.errors.txt | 30 +++++ .../instantiationLimitsCheckOrder.symbols | 78 ++++++++++++ .../instantiationLimitsCheckOrder.types | 43 +++++++ .../relationDeeplyNestedCheckOrder.symbols | 53 ++++++++ .../relationDeeplyNestedCheckOrder.types | 40 ++++++ .../relationMaybeCheckOrder.errors.txt | 31 +++++ .../compiler/relationMaybeCheckOrder.symbols | 69 ++++++++++ .../compiler/relationMaybeCheckOrder.types | 60 +++++++++ .../varianceCycleCachedResults.errors.txt | 25 ++++ .../compiler/varianceCycleCachedResults.js | 35 +++++ .../varianceCycleCachedResults.symbols | 52 ++++++++ .../compiler/varianceCycleCachedResults.types | 49 +++++++ ...rianceCycleDiscardedDiagnostics.errors.txt | 29 +++++ .../varianceCycleDiscardedDiagnostics.symbols | 71 +++++++++++ .../varianceCycleDiscardedDiagnostics.types | 63 +++++++++ .../varianceCycleEntryOrder.errors.txt | 78 ++++++++++++ .../compiler/varianceCycleEntryOrder.symbols | 106 ++++++++++++++++ .../compiler/varianceCycleEntryOrder.types | 82 ++++++++++++ ...varianceCycleStructuralFallback.errors.txt | 86 +++++++++++++ .../varianceCycleStructuralFallback.symbols | 120 ++++++++++++++++++ .../varianceCycleStructuralFallback.types | 94 ++++++++++++++ ...rianceMeasuredWithinCircularity.errors.txt | 63 +++++++++ .../varianceMeasuredWithinCircularity.symbols | 89 +++++++++++++ .../varianceMeasuredWithinCircularity.types | 52 ++++++++ ...tualCheckReentryFromOuterTypeParameters.ts | 17 +++ .../deferredTypeReferenceCycleRollback.ts | 20 +++ .../compiler/instantiationLimitsCheckOrder.ts | 25 ++++ .../relationDeeplyNestedCheckOrder.ts | 16 +++ .../cases/compiler/relationMaybeCheckOrder.ts | 24 ++++ .../compiler/varianceCycleCachedResults.ts | 24 ++++ .../varianceCycleDiscardedDiagnostics.ts | 26 ++++ .../cases/compiler/varianceCycleEntryOrder.ts | 32 +++++ .../varianceCycleStructuralFallback.ts | 33 +++++ .../varianceMeasuredWithinCircularity.ts | 30 +++++ 39 files changed, 2012 insertions(+) create mode 100644 tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.types create mode 100644 tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.types create mode 100644 tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.types create mode 100644 tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.types create mode 100644 tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.types create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.js create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.types create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.types create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.types create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.types create mode 100644 tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.types create mode 100644 tsc/testdata/tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts create mode 100644 tsc/testdata/tests/cases/compiler/deferredTypeReferenceCycleRollback.ts create mode 100644 tsc/testdata/tests/cases/compiler/instantiationLimitsCheckOrder.ts create mode 100644 tsc/testdata/tests/cases/compiler/relationDeeplyNestedCheckOrder.ts create mode 100644 tsc/testdata/tests/cases/compiler/relationMaybeCheckOrder.ts create mode 100644 tsc/testdata/tests/cases/compiler/varianceCycleCachedResults.ts create mode 100644 tsc/testdata/tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts create mode 100644 tsc/testdata/tests/cases/compiler/varianceCycleEntryOrder.ts create mode 100644 tsc/testdata/tests/cases/compiler/varianceCycleStructuralFallback.ts create mode 100644 tsc/testdata/tests/cases/compiler/varianceMeasuredWithinCircularity.ts diff --git a/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.symbols b/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.symbols new file mode 100644 index 0000000000000..88f761461324a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.symbols @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts] //// + +=== contextualCheckReentryFromOuterTypeParameters.ts === +interface Argv { +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 15)) + + command(builder: (args: Argv) => Argv, handler: (args: Arguments) => void): Argv; +>command : Symbol(Argv.command, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 24)) +>U : Symbol(U, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 12)) +>builder : Symbol(builder, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 15)) +>args : Symbol(args, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 25)) +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 15)) +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) +>U : Symbol(U, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 12)) +>handler : Symbol(handler, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 51)) +>args : Symbol(args, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 62)) +>Arguments : Symbol(Arguments, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 3, 1)) +>U : Symbol(U, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 12)) +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 15)) + + option(key: K, options: O): Argv<{ [key in K]: O } & Check>; +>option : Symbol(Argv.option, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 100)) +>K : Symbol(K, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 11)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 28)) +>key : Symbol(key, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 32)) +>K : Symbol(K, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 11)) +>options : Symbol(options, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 39)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 28)) +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) +>key : Symbol(key, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 61)) +>K : Symbol(K, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 11)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 28)) +>Check : Symbol(Check, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 78)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 2, 28)) +} +type Arguments = { [key in keyof T]: T[key] } & { [key: string]: unknown }; +>Arguments : Symbol(Arguments, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 3, 1)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 15)) +>key : Symbol(key, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 23)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 15)) +>T : Symbol(T, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 15)) +>key : Symbol(key, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 23)) +>key : Symbol(key, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 54)) + +type Check = O extends {} ? {} : {}; +>Check : Symbol(Check, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 4, 78)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 5, 11)) +>O : Symbol(O, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 5, 11)) + +declare const yargs: Argv; +>yargs : Symbol(yargs, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 6, 13)) +>Argv : Symbol(Argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 0)) + +yargs.command( +>yargs.command : Symbol(Argv.command, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 24)) +>yargs : Symbol(yargs, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 6, 13)) +>command : Symbol(Argv.command, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 0, 24)) + + (yargs) => yargs.option("a", { type: "string" }), +>yargs : Symbol(yargs, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 9, 5)) +>yargs.option : Symbol(Argv.option, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 100)) +>yargs : Symbol(yargs, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 9, 5)) +>option : Symbol(Argv.option, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 1, 100)) +>type : Symbol(type, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 9, 34)) + + (argv) => { +>argv : Symbol(argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 10, 5)) + + const a: { type: string } = argv.a; +>a : Symbol(a, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 11, 13)) +>type : Symbol(type, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 11, 18)) +>argv.a : Symbol(a) +>argv : Symbol(argv, Decl(contextualCheckReentryFromOuterTypeParameters.ts, 10, 5)) +>a : Symbol(a) + + }, +); + diff --git a/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.types b/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.types new file mode 100644 index 0000000000000..bd12f97face3b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/contextualCheckReentryFromOuterTypeParameters.types @@ -0,0 +1,58 @@ +//// [tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts] //// + +=== contextualCheckReentryFromOuterTypeParameters.ts === +interface Argv { + command(builder: (args: Argv) => Argv, handler: (args: Arguments) => void): Argv; +>command : (builder: (args: Argv) => Argv, handler: (args: Arguments) => void) => Argv +>builder : (args: Argv) => Argv +>args : Argv +>handler : (args: Arguments) => void +>args : Arguments + + option(key: K, options: O): Argv<{ [key in K]: O } & Check>; +>option : (key: K, options: O) => Argv<{ [key in K]: O; } & Check> +>key : K +>options : O +} +type Arguments = { [key in keyof T]: T[key] } & { [key: string]: unknown }; +>Arguments : Arguments +>key : string + +type Check = O extends {} ? {} : {}; +>Check : Check + +declare const yargs: Argv; +>yargs : Argv<{}> + +yargs.command( +>yargs.command( (yargs) => yargs.option("a", { type: "string" }), (argv) => { const a: { type: string } = argv.a; },) : Argv<{}> +>yargs.command : (builder: (args: Argv<{}>) => Argv, handler: (args: Arguments) => void) => Argv<{}> +>yargs : Argv<{}> +>command : (builder: (args: Argv<{}>) => Argv, handler: (args: Arguments) => void) => Argv<{}> + + (yargs) => yargs.option("a", { type: "string" }), +>(yargs) => yargs.option("a", { type: "string" }) : (yargs: Argv<{}>) => Argv<{ a: { type: string; }; }> +>yargs : Argv<{}> +>yargs.option("a", { type: "string" }) : Argv<{ a: { type: string; }; }> +>yargs.option : (key: K, options: O) => Argv<{ [key in K]: O; } & Check> +>yargs : Argv<{}> +>option : (key: K, options: O) => Argv<{ [key in K]: O; } & Check> +>"a" : "a" +>{ type: "string" } : { type: string; } +>type : string +>"string" : "string" + + (argv) => { +>(argv) => { const a: { type: string } = argv.a; } : (argv: Arguments<{ a: { type: string; }; }>) => void +>argv : Arguments<{ a: { type: string; }; }> + + const a: { type: string } = argv.a; +>a : { type: string; } +>type : string +>argv.a : { type: string; } +>argv : Arguments<{ a: { type: string; }; }> +>a : { type: string; } + + }, +); + diff --git a/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.errors.txt b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.errors.txt new file mode 100644 index 0000000000000..88bdce38b167c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.errors.txt @@ -0,0 +1,24 @@ +deferredTypeReferenceCycleRollback.ts(17,31): error TS2304: Cannot find name 'Missing'. + + +==== deferredTypeReferenceCycleRollback.ts (1 errors) ==== + // A cycle rollback used to reset the type of the Array> + // node while the deferred reference identified by that node survived, + // which crashed a later instantiation of it. + + declare function declare(): void; + + interface PluginObj { + visitor: Visit; + } + type Visit = VisitFn | VisitObj; + type VisitFn = (path: NodePath

) => void; + interface VisitObj {} + declare class NodePath { + parentPath: NodePath>; + get: Get; + } + type Get = T extends Array ? Array> : never; + ~~~~~~~ +!!! error TS2304: Cannot find name 'Missing'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.symbols b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.symbols new file mode 100644 index 0000000000000..285889376a2ba --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.symbols @@ -0,0 +1,70 @@ +//// [tests/cases/compiler/deferredTypeReferenceCycleRollback.ts] //// + +=== deferredTypeReferenceCycleRollback.ts === +// A cycle rollback used to reset the type of the Array> +// node while the deferred reference identified by that node survived, +// which crashed a later instantiation of it. + +declare function declare(): void; +>declare : Symbol(declare, Decl(deferredTypeReferenceCycleRollback.ts, 0, 0)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 4, 25)) +>PluginObj : Symbol(PluginObj, Decl(deferredTypeReferenceCycleRollback.ts, 4, 66)) +>PluginObj : Symbol(PluginObj, Decl(deferredTypeReferenceCycleRollback.ts, 4, 66)) + +interface PluginObj { +>PluginObj : Symbol(PluginObj, Decl(deferredTypeReferenceCycleRollback.ts, 4, 66)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 6, 20)) + + visitor: Visit; +>visitor : Symbol(PluginObj.visitor, Decl(deferredTypeReferenceCycleRollback.ts, 6, 34)) +>Visit : Symbol(Visit, Decl(deferredTypeReferenceCycleRollback.ts, 8, 1)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 6, 20)) +} +type Visit = VisitFn | VisitObj; +>Visit : Symbol(Visit, Decl(deferredTypeReferenceCycleRollback.ts, 8, 1)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 9, 11)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 9, 13)) +>VisitFn : Symbol(VisitFn, Decl(deferredTypeReferenceCycleRollback.ts, 9, 50)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 9, 11)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 9, 13)) +>VisitObj : Symbol(VisitObj, Decl(deferredTypeReferenceCycleRollback.ts, 10, 49)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 9, 11)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 9, 13)) + +type VisitFn = (path: NodePath

) => void; +>VisitFn : Symbol(VisitFn, Decl(deferredTypeReferenceCycleRollback.ts, 9, 50)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 10, 13)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 10, 15)) +>path : Symbol(path, Decl(deferredTypeReferenceCycleRollback.ts, 10, 22)) +>NodePath : Symbol(NodePath, Decl(deferredTypeReferenceCycleRollback.ts, 11, 27)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 10, 15)) + +interface VisitObj {} +>VisitObj : Symbol(VisitObj, Decl(deferredTypeReferenceCycleRollback.ts, 10, 49)) +>S : Symbol(S, Decl(deferredTypeReferenceCycleRollback.ts, 11, 19)) +>P : Symbol(P, Decl(deferredTypeReferenceCycleRollback.ts, 11, 21)) + +declare class NodePath { +>NodePath : Symbol(NodePath, Decl(deferredTypeReferenceCycleRollback.ts, 11, 27)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 12, 23)) + + parentPath: NodePath>; +>parentPath : Symbol(NodePath.parentPath, Decl(deferredTypeReferenceCycleRollback.ts, 12, 27)) +>NodePath : Symbol(NodePath, Decl(deferredTypeReferenceCycleRollback.ts, 11, 27)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 12, 23)) + + get: Get; +>get : Symbol(NodePath.get, Decl(deferredTypeReferenceCycleRollback.ts, 13, 43)) +>Get : Symbol(Get, Decl(deferredTypeReferenceCycleRollback.ts, 15, 1)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 12, 23)) +} +type Get = T extends Array ? Array> : never; +>Get : Symbol(Get, Decl(deferredTypeReferenceCycleRollback.ts, 15, 1)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 16, 9)) +>T : Symbol(T, Decl(deferredTypeReferenceCycleRollback.ts, 16, 9)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) +>Missing : Symbol(Missing) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) +>NodePath : Symbol(NodePath, Decl(deferredTypeReferenceCycleRollback.ts, 11, 27)) + diff --git a/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.types b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.types new file mode 100644 index 0000000000000..7db259991a1ca --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/deferredTypeReferenceCycleRollback.types @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/deferredTypeReferenceCycleRollback.ts] //// + +=== deferredTypeReferenceCycleRollback.ts === +// A cycle rollback used to reset the type of the Array> +// node while the deferred reference identified by that node survived, +// which crashed a later instantiation of it. + +declare function declare(): void; +>declare : >() => void + +interface PluginObj { + visitor: Visit; +>visitor : Visit +} +type Visit = VisitFn | VisitObj; +>Visit : Visit + +type VisitFn = (path: NodePath

) => void; +>VisitFn : VisitFn +>path : NodePath

+ +interface VisitObj {} +declare class NodePath { +>NodePath : NodePath + + parentPath: NodePath>; +>parentPath : NodePath> + + get: Get; +>get : Get +} +type Get = T extends Array ? Array> : never; +>Get : Get + diff --git a/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.errors.txt b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.errors.txt new file mode 100644 index 0000000000000..267ec02b4f194 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.errors.txt @@ -0,0 +1,30 @@ +instantiationLimitsCheckOrder.ts(11,16): error TS2589: Type instantiation is excessively deep and possibly infinite. + + +==== instantiationLimitsCheckOrder.ts (1 errors) ==== + // Instantiation limits must not depend on what was instantiated before. + // This holds for the depth limit, but not yet for the limit on the number + // of instantiations, which Wide2All only reaches if Wide2Tail was not + // checked first. + + type D = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; + type K = `${D}${D}${D}`; + + // Over five million instantiations for one statement. + type Wide = N["length"] extends 6 ? I : { [J in K]: Wide<[...N, 0], [J, I][0]> }[K]; + type WideAll = Wide<[], "">; + ~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + // The same, but half of the instantiations already happened for another + // statement. + type Wide2 = N["length"] extends 6 ? I : { [J in K]: Wide2<[...N, 0], [J, I][0]> }[K]; + type Wide2Tail = Wide2<[0, 0, 0], "">; + type Wide2All = Wide2<[], "">; + + // Over a hundred nested instantiations, half of which already happened for + // another statement. + type Deep = N["length"] extends 60 ? never : Deep<[...N, 0]> | N["length"]; + type DeepTail = Deep<[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]>; + type DeepAll = Deep<[]>; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.symbols b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.symbols new file mode 100644 index 0000000000000..addc79a296cf8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.symbols @@ -0,0 +1,78 @@ +//// [tests/cases/compiler/instantiationLimitsCheckOrder.ts] //// + +=== instantiationLimitsCheckOrder.ts === +// Instantiation limits must not depend on what was instantiated before. +// This holds for the depth limit, but not yet for the limit on the number +// of instantiations, which Wide2All only reaches if Wide2Tail was not +// checked first. + +type D = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; +>D : Symbol(D, Decl(instantiationLimitsCheckOrder.ts, 0, 0)) + +type K = `${D}${D}${D}`; +>K : Symbol(K, Decl(instantiationLimitsCheckOrder.ts, 5, 47)) +>D : Symbol(D, Decl(instantiationLimitsCheckOrder.ts, 0, 0)) +>D : Symbol(D, Decl(instantiationLimitsCheckOrder.ts, 0, 0)) +>D : Symbol(D, Decl(instantiationLimitsCheckOrder.ts, 0, 0)) + +// Over five million instantiations for one statement. +type Wide = N["length"] extends 6 ? I : { [J in K]: Wide<[...N, 0], [J, I][0]> }[K]; +>Wide : Symbol(Wide, Decl(instantiationLimitsCheckOrder.ts, 6, 24)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 9, 10)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 9, 24)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 9, 10)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 9, 24)) +>J : Symbol(J, Decl(instantiationLimitsCheckOrder.ts, 9, 61)) +>K : Symbol(K, Decl(instantiationLimitsCheckOrder.ts, 5, 47)) +>Wide : Symbol(Wide, Decl(instantiationLimitsCheckOrder.ts, 6, 24)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 9, 10)) +>J : Symbol(J, Decl(instantiationLimitsCheckOrder.ts, 9, 61)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 9, 24)) +>K : Symbol(K, Decl(instantiationLimitsCheckOrder.ts, 5, 47)) + +type WideAll = Wide<[], "">; +>WideAll : Symbol(WideAll, Decl(instantiationLimitsCheckOrder.ts, 9, 102)) +>Wide : Symbol(Wide, Decl(instantiationLimitsCheckOrder.ts, 6, 24)) + +// The same, but half of the instantiations already happened for another +// statement. +type Wide2 = N["length"] extends 6 ? I : { [J in K]: Wide2<[...N, 0], [J, I][0]> }[K]; +>Wide2 : Symbol(Wide2, Decl(instantiationLimitsCheckOrder.ts, 10, 28)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 14, 11)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 14, 25)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 14, 11)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 14, 25)) +>J : Symbol(J, Decl(instantiationLimitsCheckOrder.ts, 14, 62)) +>K : Symbol(K, Decl(instantiationLimitsCheckOrder.ts, 5, 47)) +>Wide2 : Symbol(Wide2, Decl(instantiationLimitsCheckOrder.ts, 10, 28)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 14, 11)) +>J : Symbol(J, Decl(instantiationLimitsCheckOrder.ts, 14, 62)) +>I : Symbol(I, Decl(instantiationLimitsCheckOrder.ts, 14, 25)) +>K : Symbol(K, Decl(instantiationLimitsCheckOrder.ts, 5, 47)) + +type Wide2Tail = Wide2<[0, 0, 0], "">; +>Wide2Tail : Symbol(Wide2Tail, Decl(instantiationLimitsCheckOrder.ts, 14, 104)) +>Wide2 : Symbol(Wide2, Decl(instantiationLimitsCheckOrder.ts, 10, 28)) + +type Wide2All = Wide2<[], "">; +>Wide2All : Symbol(Wide2All, Decl(instantiationLimitsCheckOrder.ts, 15, 38)) +>Wide2 : Symbol(Wide2, Decl(instantiationLimitsCheckOrder.ts, 10, 28)) + +// Over a hundred nested instantiations, half of which already happened for +// another statement. +type Deep = N["length"] extends 60 ? never : Deep<[...N, 0]> | N["length"]; +>Deep : Symbol(Deep, Decl(instantiationLimitsCheckOrder.ts, 16, 30)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 20, 10)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 20, 10)) +>Deep : Symbol(Deep, Decl(instantiationLimitsCheckOrder.ts, 16, 30)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 20, 10)) +>N : Symbol(N, Decl(instantiationLimitsCheckOrder.ts, 20, 10)) + +type DeepTail = Deep<[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]>; +>DeepTail : Symbol(DeepTail, Decl(instantiationLimitsCheckOrder.ts, 20, 90)) +>Deep : Symbol(Deep, Decl(instantiationLimitsCheckOrder.ts, 16, 30)) + +type DeepAll = Deep<[]>; +>DeepAll : Symbol(DeepAll, Decl(instantiationLimitsCheckOrder.ts, 21, 113)) +>Deep : Symbol(Deep, Decl(instantiationLimitsCheckOrder.ts, 16, 30)) + diff --git a/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.types b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.types new file mode 100644 index 0000000000000..821c937b08c1d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/instantiationLimitsCheckOrder.types @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/instantiationLimitsCheckOrder.ts] //// + +=== instantiationLimitsCheckOrder.ts === +// Instantiation limits must not depend on what was instantiated before. +// This holds for the depth limit, but not yet for the limit on the number +// of instantiations, which Wide2All only reaches if Wide2Tail was not +// checked first. + +type D = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; +>D : D + +type K = `${D}${D}${D}`; +>K : "000" | "001" | "002" | "003" | "004" | "005" | "006" | "007" | "008" | "009" | "010" | "011" | "012" | "013" | "014" | "015" | "016" | "017" | "018" | "019" | "020" | "021" | "022" | "023" | "024" | "025" | "026" | "027" | "028" | "029" | "030" | "031" | "032" | "033" | "034" | "035" | "036" | "037" | "038" | "039" | "040" | "041" | "042" | "043" | "044" | "045" | "046" | "047" | "048" | "049" | "050" | "051" | "052" | "053" | "054" | "055" | "056" | "057" | "058" | "059" | "060" | "061" | "062" | "063" | "064" | "065" | "066" | "067" | "068" | "069" | "070" | "071" | "072" | "073" | "074" | "075" | "076" | "077" | "078" | "079" | "080" | "081" | "082" | "083" | "084" | "085" | "086" | "087" | "088" | "089" | "090" | "091" | "092" | "093" | "094" | "095" | "096" | "097" | "098" | "099" | "100" | "101" | "102" | "103" | "104" | "105" | "106" | "107" | "108" | "109" | "110" | "111" | "112" | "113" | "114" | "115" | "116" | "117" | "118" | "119" | "120" | "121" | "122" | "123" | "124" | "125" | "126" | "127" | "128" | "129" | "130" | "131" | "132" | "133" | "134" | "135" | "136" | "137" | "138" | "139" | "140" | "141" | "142" | "143" | "144" | "145" | "146" | "147" | "148" | "149" | "150" | "151" | "152" | "153" | "154" | "155" | "156" | "157" | "158" | "159" | "160" | "161" | "162" | "163" | "164" | "165" | "166" | "167" | "168" | "169" | "170" | "171" | "172" | "173" | "174" | "175" | "176" | "177" | "178" | "179" | "180" | "181" | "182" | "183" | "184" | "185" | "186" | "187" | "188" | "189" | "190" | "191" | "192" | "193" | "194" | "195" | "196" | "197" | "198" | "199" | "200" | "201" | "202" | "203" | "204" | "205" | "206" | "207" | "208" | "209" | "210" | "211" | "212" | "213" | "214" | "215" | "216" | "217" | "218" | "219" | "220" | "221" | "222" | "223" | "224" | "225" | "226" | "227" | "228" | "229" | "230" | "231" | "232" | "233" | "234" | "235" | "236" | "237" | "238" | "239" | "240" | "241" | "242" | "243" | "244" | "245" | "246" | "247" | "248" | "249" | "250" | "251" | "252" | "253" | "254" | "255" | "256" | "257" | "258" | "259" | "260" | "261" | "262" | "263" | "264" | "265" | "266" | "267" | "268" | "269" | "270" | "271" | "272" | "273" | "274" | "275" | "276" | "277" | "278" | "279" | "280" | "281" | "282" | "283" | "284" | "285" | "286" | "287" | "288" | "289" | "290" | "291" | "292" | "293" | "294" | "295" | "296" | "297" | "298" | "299" | "300" | "301" | "302" | "303" | "304" | "305" | "306" | "307" | "308" | "309" | "310" | "311" | "312" | "313" | "314" | "315" | "316" | "317" | "318" | "319" | "320" | "321" | "322" | "323" | "324" | "325" | "326" | "327" | "328" | "329" | "330" | "331" | "332" | "333" | "334" | "335" | "336" | "337" | "338" | "339" | "340" | "341" | "342" | "343" | "344" | "345" | "346" | "347" | "348" | "349" | "350" | "351" | "352" | "353" | "354" | "355" | "356" | "357" | "358" | "359" | "360" | "361" | "362" | "363" | "364" | "365" | "366" | "367" | "368" | "369" | "370" | "371" | "372" | "373" | "374" | "375" | "376" | "377" | "378" | "379" | "380" | "381" | "382" | "383" | "384" | "385" | "386" | "387" | "388" | "389" | "390" | "391" | "392" | "393" | "394" | "395" | "396" | "397" | "398" | "399" | "400" | "401" | "402" | "403" | "404" | "405" | "406" | "407" | "408" | "409" | "410" | "411" | "412" | "413" | "414" | "415" | "416" | "417" | "418" | "419" | "420" | "421" | "422" | "423" | "424" | "425" | "426" | "427" | "428" | "429" | "430" | "431" | "432" | "433" | "434" | "435" | "436" | "437" | "438" | "439" | "440" | "441" | "442" | "443" | "444" | "445" | "446" | "447" | "448" | "449" | "450" | "451" | "452" | "453" | "454" | "455" | "456" | "457" | "458" | "459" | "460" | "461" | "462" | "463" | "464" | "465" | "466" | "467" | "468" | "469" | "470" | "471" | "472" | "473" | "474" | "475" | "476" | "477" | "478" | "479" | "480" | "481" | "482" | "483" | "484" | "485" | "486" | "487" | "488" | "489" | "490" | "491" | "492" | "493" | "494" | "495" | "496" | "497" | "498" | "499" | "500" | "501" | "502" | "503" | "504" | "505" | "506" | "507" | "508" | "509" | "510" | "511" | "512" | "513" | "514" | "515" | "516" | "517" | "518" | "519" | "520" | "521" | "522" | "523" | "524" | "525" | "526" | "527" | "528" | "529" | "530" | "531" | "532" | "533" | "534" | "535" | "536" | "537" | "538" | "539" | "540" | "541" | "542" | "543" | "544" | "545" | "546" | "547" | "548" | "549" | "550" | "551" | "552" | "553" | "554" | "555" | "556" | "557" | "558" | "559" | "560" | "561" | "562" | "563" | "564" | "565" | "566" | "567" | "568" | "569" | "570" | "571" | "572" | "573" | "574" | "575" | "576" | "577" | "578" | "579" | "580" | "581" | "582" | "583" | "584" | "585" | "586" | "587" | "588" | "589" | "590" | "591" | "592" | "593" | "594" | "595" | "596" | "597" | "598" | "599" | "600" | "601" | "602" | "603" | "604" | "605" | "606" | "607" | "608" | "609" | "610" | "611" | "612" | "613" | "614" | "615" | "616" | "617" | "618" | "619" | "620" | "621" | "622" | "623" | "624" | "625" | "626" | "627" | "628" | "629" | "630" | "631" | "632" | "633" | "634" | "635" | "636" | "637" | "638" | "639" | "640" | "641" | "642" | "643" | "644" | "645" | "646" | "647" | "648" | "649" | "650" | "651" | "652" | "653" | "654" | "655" | "656" | "657" | "658" | "659" | "660" | "661" | "662" | "663" | "664" | "665" | "666" | "667" | "668" | "669" | "670" | "671" | "672" | "673" | "674" | "675" | "676" | "677" | "678" | "679" | "680" | "681" | "682" | "683" | "684" | "685" | "686" | "687" | "688" | "689" | "690" | "691" | "692" | "693" | "694" | "695" | "696" | "697" | "698" | "699" | "700" | "701" | "702" | "703" | "704" | "705" | "706" | "707" | "708" | "709" | "710" | "711" | "712" | "713" | "714" | "715" | "716" | "717" | "718" | "719" | "720" | "721" | "722" | "723" | "724" | "725" | "726" | "727" | "728" | "729" | "730" | "731" | "732" | "733" | "734" | "735" | "736" | "737" | "738" | "739" | "740" | "741" | "742" | "743" | "744" | "745" | "746" | "747" | "748" | "749" | "750" | "751" | "752" | "753" | "754" | "755" | "756" | "757" | "758" | "759" | "760" | "761" | "762" | "763" | "764" | "765" | "766" | "767" | "768" | "769" | "770" | "771" | "772" | "773" | "774" | "775" | "776" | "777" | "778" | "779" | "780" | "781" | "782" | "783" | "784" | "785" | "786" | "787" | "788" | "789" | "790" | "791" | "792" | "793" | "794" | "795" | "796" | "797" | "798" | "799" | "800" | "801" | "802" | "803" | "804" | "805" | "806" | "807" | "808" | "809" | "810" | "811" | "812" | "813" | "814" | "815" | "816" | "817" | "818" | "819" | "820" | "821" | "822" | "823" | "824" | "825" | "826" | "827" | "828" | "829" | "830" | "831" | "832" | "833" | "834" | "835" | "836" | "837" | "838" | "839" | "840" | "841" | "842" | "843" | "844" | "845" | "846" | "847" | "848" | "849" | "850" | "851" | "852" | "853" | "854" | "855" | "856" | "857" | "858" | "859" | "860" | "861" | "862" | "863" | "864" | "865" | "866" | "867" | "868" | "869" | "870" | "871" | "872" | "873" | "874" | "875" | "876" | "877" | "878" | "879" | "880" | "881" | "882" | "883" | "884" | "885" | "886" | "887" | "888" | "889" | "890" | "891" | "892" | "893" | "894" | "895" | "896" | "897" | "898" | "899" | "900" | "901" | "902" | "903" | "904" | "905" | "906" | "907" | "908" | "909" | "910" | "911" | "912" | "913" | "914" | "915" | "916" | "917" | "918" | "919" | "920" | "921" | "922" | "923" | "924" | "925" | "926" | "927" | "928" | "929" | "930" | "931" | "932" | "933" | "934" | "935" | "936" | "937" | "938" | "939" | "940" | "941" | "942" | "943" | "944" | "945" | "946" | "947" | "948" | "949" | "950" | "951" | "952" | "953" | "954" | "955" | "956" | "957" | "958" | "959" | "960" | "961" | "962" | "963" | "964" | "965" | "966" | "967" | "968" | "969" | "970" | "971" | "972" | "973" | "974" | "975" | "976" | "977" | "978" | "979" | "980" | "981" | "982" | "983" | "984" | "985" | "986" | "987" | "988" | "989" | "990" | "991" | "992" | "993" | "994" | "995" | "996" | "997" | "998" | "999" + +// Over five million instantiations for one statement. +type Wide = N["length"] extends 6 ? I : { [J in K]: Wide<[...N, 0], [J, I][0]> }[K]; +>Wide : Wide + +type WideAll = Wide<[], "">; +>WideAll : any + +// The same, but half of the instantiations already happened for another +// statement. +type Wide2 = N["length"] extends 6 ? I : { [J in K]: Wide2<[...N, 0], [J, I][0]> }[K]; +>Wide2 : Wide2 + +type Wide2Tail = Wide2<[0, 0, 0], "">; +>Wide2Tail : "000" | "001" | "002" | "003" | "004" | "005" | "006" | "007" | "008" | "009" | "010" | "011" | "012" | "013" | "014" | "015" | "016" | "017" | "018" | "019" | "020" | "021" | "022" | "023" | "024" | "025" | "026" | "027" | "028" | "029" | "030" | "031" | "032" | "033" | "034" | "035" | "036" | "037" | "038" | "039" | "040" | "041" | "042" | "043" | "044" | "045" | "046" | "047" | "048" | "049" | "050" | "051" | "052" | "053" | "054" | "055" | "056" | "057" | "058" | "059" | "060" | "061" | "062" | "063" | "064" | "065" | "066" | "067" | "068" | "069" | "070" | "071" | "072" | "073" | "074" | "075" | "076" | "077" | "078" | "079" | "080" | "081" | "082" | "083" | "084" | "085" | "086" | "087" | "088" | "089" | "090" | "091" | "092" | "093" | "094" | "095" | "096" | "097" | "098" | "099" | "100" | "101" | "102" | "103" | "104" | "105" | "106" | "107" | "108" | "109" | "110" | "111" | "112" | "113" | "114" | "115" | "116" | "117" | "118" | "119" | "120" | "121" | "122" | "123" | "124" | "125" | "126" | "127" | "128" | "129" | "130" | "131" | "132" | "133" | "134" | "135" | "136" | "137" | "138" | "139" | "140" | "141" | "142" | "143" | "144" | "145" | "146" | "147" | "148" | "149" | "150" | "151" | "152" | "153" | "154" | "155" | "156" | "157" | "158" | "159" | "160" | "161" | "162" | "163" | "164" | "165" | "166" | "167" | "168" | "169" | "170" | "171" | "172" | "173" | "174" | "175" | "176" | "177" | "178" | "179" | "180" | "181" | "182" | "183" | "184" | "185" | "186" | "187" | "188" | "189" | "190" | "191" | "192" | "193" | "194" | "195" | "196" | "197" | "198" | "199" | "200" | "201" | "202" | "203" | "204" | "205" | "206" | "207" | "208" | "209" | "210" | "211" | "212" | "213" | "214" | "215" | "216" | "217" | "218" | "219" | "220" | "221" | "222" | "223" | "224" | "225" | "226" | "227" | "228" | "229" | "230" | "231" | "232" | "233" | "234" | "235" | "236" | "237" | "238" | "239" | "240" | "241" | "242" | "243" | "244" | "245" | "246" | "247" | "248" | "249" | "250" | "251" | "252" | "253" | "254" | "255" | "256" | "257" | "258" | "259" | "260" | "261" | "262" | "263" | "264" | "265" | "266" | "267" | "268" | "269" | "270" | "271" | "272" | "273" | "274" | "275" | "276" | "277" | "278" | "279" | "280" | "281" | "282" | "283" | "284" | "285" | "286" | "287" | "288" | "289" | "290" | "291" | "292" | "293" | "294" | "295" | "296" | "297" | "298" | "299" | "300" | "301" | "302" | "303" | "304" | "305" | "306" | "307" | "308" | "309" | "310" | "311" | "312" | "313" | "314" | "315" | "316" | "317" | "318" | "319" | "320" | "321" | "322" | "323" | "324" | "325" | "326" | "327" | "328" | "329" | "330" | "331" | "332" | "333" | "334" | "335" | "336" | "337" | "338" | "339" | "340" | "341" | "342" | "343" | "344" | "345" | "346" | "347" | "348" | "349" | "350" | "351" | "352" | "353" | "354" | "355" | "356" | "357" | "358" | "359" | "360" | "361" | "362" | "363" | "364" | "365" | "366" | "367" | "368" | "369" | "370" | "371" | "372" | "373" | "374" | "375" | "376" | "377" | "378" | "379" | "380" | "381" | "382" | "383" | "384" | "385" | "386" | "387" | "388" | "389" | "390" | "391" | "392" | "393" | "394" | "395" | "396" | "397" | "398" | "399" | "400" | "401" | "402" | "403" | "404" | "405" | "406" | "407" | "408" | "409" | "410" | "411" | "412" | "413" | "414" | "415" | "416" | "417" | "418" | "419" | "420" | "421" | "422" | "423" | "424" | "425" | "426" | "427" | "428" | "429" | "430" | "431" | "432" | "433" | "434" | "435" | "436" | "437" | "438" | "439" | "440" | "441" | "442" | "443" | "444" | "445" | "446" | "447" | "448" | "449" | "450" | "451" | "452" | "453" | "454" | "455" | "456" | "457" | "458" | "459" | "460" | "461" | "462" | "463" | "464" | "465" | "466" | "467" | "468" | "469" | "470" | "471" | "472" | "473" | "474" | "475" | "476" | "477" | "478" | "479" | "480" | "481" | "482" | "483" | "484" | "485" | "486" | "487" | "488" | "489" | "490" | "491" | "492" | "493" | "494" | "495" | "496" | "497" | "498" | "499" | "500" | "501" | "502" | "503" | "504" | "505" | "506" | "507" | "508" | "509" | "510" | "511" | "512" | "513" | "514" | "515" | "516" | "517" | "518" | "519" | "520" | "521" | "522" | "523" | "524" | "525" | "526" | "527" | "528" | "529" | "530" | "531" | "532" | "533" | "534" | "535" | "536" | "537" | "538" | "539" | "540" | "541" | "542" | "543" | "544" | "545" | "546" | "547" | "548" | "549" | "550" | "551" | "552" | "553" | "554" | "555" | "556" | "557" | "558" | "559" | "560" | "561" | "562" | "563" | "564" | "565" | "566" | "567" | "568" | "569" | "570" | "571" | "572" | "573" | "574" | "575" | "576" | "577" | "578" | "579" | "580" | "581" | "582" | "583" | "584" | "585" | "586" | "587" | "588" | "589" | "590" | "591" | "592" | "593" | "594" | "595" | "596" | "597" | "598" | "599" | "600" | "601" | "602" | "603" | "604" | "605" | "606" | "607" | "608" | "609" | "610" | "611" | "612" | "613" | "614" | "615" | "616" | "617" | "618" | "619" | "620" | "621" | "622" | "623" | "624" | "625" | "626" | "627" | "628" | "629" | "630" | "631" | "632" | "633" | "634" | "635" | "636" | "637" | "638" | "639" | "640" | "641" | "642" | "643" | "644" | "645" | "646" | "647" | "648" | "649" | "650" | "651" | "652" | "653" | "654" | "655" | "656" | "657" | "658" | "659" | "660" | "661" | "662" | "663" | "664" | "665" | "666" | "667" | "668" | "669" | "670" | "671" | "672" | "673" | "674" | "675" | "676" | "677" | "678" | "679" | "680" | "681" | "682" | "683" | "684" | "685" | "686" | "687" | "688" | "689" | "690" | "691" | "692" | "693" | "694" | "695" | "696" | "697" | "698" | "699" | "700" | "701" | "702" | "703" | "704" | "705" | "706" | "707" | "708" | "709" | "710" | "711" | "712" | "713" | "714" | "715" | "716" | "717" | "718" | "719" | "720" | "721" | "722" | "723" | "724" | "725" | "726" | "727" | "728" | "729" | "730" | "731" | "732" | "733" | "734" | "735" | "736" | "737" | "738" | "739" | "740" | "741" | "742" | "743" | "744" | "745" | "746" | "747" | "748" | "749" | "750" | "751" | "752" | "753" | "754" | "755" | "756" | "757" | "758" | "759" | "760" | "761" | "762" | "763" | "764" | "765" | "766" | "767" | "768" | "769" | "770" | "771" | "772" | "773" | "774" | "775" | "776" | "777" | "778" | "779" | "780" | "781" | "782" | "783" | "784" | "785" | "786" | "787" | "788" | "789" | "790" | "791" | "792" | "793" | "794" | "795" | "796" | "797" | "798" | "799" | "800" | "801" | "802" | "803" | "804" | "805" | "806" | "807" | "808" | "809" | "810" | "811" | "812" | "813" | "814" | "815" | "816" | "817" | "818" | "819" | "820" | "821" | "822" | "823" | "824" | "825" | "826" | "827" | "828" | "829" | "830" | "831" | "832" | "833" | "834" | "835" | "836" | "837" | "838" | "839" | "840" | "841" | "842" | "843" | "844" | "845" | "846" | "847" | "848" | "849" | "850" | "851" | "852" | "853" | "854" | "855" | "856" | "857" | "858" | "859" | "860" | "861" | "862" | "863" | "864" | "865" | "866" | "867" | "868" | "869" | "870" | "871" | "872" | "873" | "874" | "875" | "876" | "877" | "878" | "879" | "880" | "881" | "882" | "883" | "884" | "885" | "886" | "887" | "888" | "889" | "890" | "891" | "892" | "893" | "894" | "895" | "896" | "897" | "898" | "899" | "900" | "901" | "902" | "903" | "904" | "905" | "906" | "907" | "908" | "909" | "910" | "911" | "912" | "913" | "914" | "915" | "916" | "917" | "918" | "919" | "920" | "921" | "922" | "923" | "924" | "925" | "926" | "927" | "928" | "929" | "930" | "931" | "932" | "933" | "934" | "935" | "936" | "937" | "938" | "939" | "940" | "941" | "942" | "943" | "944" | "945" | "946" | "947" | "948" | "949" | "950" | "951" | "952" | "953" | "954" | "955" | "956" | "957" | "958" | "959" | "960" | "961" | "962" | "963" | "964" | "965" | "966" | "967" | "968" | "969" | "970" | "971" | "972" | "973" | "974" | "975" | "976" | "977" | "978" | "979" | "980" | "981" | "982" | "983" | "984" | "985" | "986" | "987" | "988" | "989" | "990" | "991" | "992" | "993" | "994" | "995" | "996" | "997" | "998" | "999" + +type Wide2All = Wide2<[], "">; +>Wide2All : "000" | "001" | "002" | "003" | "004" | "005" | "006" | "007" | "008" | "009" | "010" | "011" | "012" | "013" | "014" | "015" | "016" | "017" | "018" | "019" | "020" | "021" | "022" | "023" | "024" | "025" | "026" | "027" | "028" | "029" | "030" | "031" | "032" | "033" | "034" | "035" | "036" | "037" | "038" | "039" | "040" | "041" | "042" | "043" | "044" | "045" | "046" | "047" | "048" | "049" | "050" | "051" | "052" | "053" | "054" | "055" | "056" | "057" | "058" | "059" | "060" | "061" | "062" | "063" | "064" | "065" | "066" | "067" | "068" | "069" | "070" | "071" | "072" | "073" | "074" | "075" | "076" | "077" | "078" | "079" | "080" | "081" | "082" | "083" | "084" | "085" | "086" | "087" | "088" | "089" | "090" | "091" | "092" | "093" | "094" | "095" | "096" | "097" | "098" | "099" | "100" | "101" | "102" | "103" | "104" | "105" | "106" | "107" | "108" | "109" | "110" | "111" | "112" | "113" | "114" | "115" | "116" | "117" | "118" | "119" | "120" | "121" | "122" | "123" | "124" | "125" | "126" | "127" | "128" | "129" | "130" | "131" | "132" | "133" | "134" | "135" | "136" | "137" | "138" | "139" | "140" | "141" | "142" | "143" | "144" | "145" | "146" | "147" | "148" | "149" | "150" | "151" | "152" | "153" | "154" | "155" | "156" | "157" | "158" | "159" | "160" | "161" | "162" | "163" | "164" | "165" | "166" | "167" | "168" | "169" | "170" | "171" | "172" | "173" | "174" | "175" | "176" | "177" | "178" | "179" | "180" | "181" | "182" | "183" | "184" | "185" | "186" | "187" | "188" | "189" | "190" | "191" | "192" | "193" | "194" | "195" | "196" | "197" | "198" | "199" | "200" | "201" | "202" | "203" | "204" | "205" | "206" | "207" | "208" | "209" | "210" | "211" | "212" | "213" | "214" | "215" | "216" | "217" | "218" | "219" | "220" | "221" | "222" | "223" | "224" | "225" | "226" | "227" | "228" | "229" | "230" | "231" | "232" | "233" | "234" | "235" | "236" | "237" | "238" | "239" | "240" | "241" | "242" | "243" | "244" | "245" | "246" | "247" | "248" | "249" | "250" | "251" | "252" | "253" | "254" | "255" | "256" | "257" | "258" | "259" | "260" | "261" | "262" | "263" | "264" | "265" | "266" | "267" | "268" | "269" | "270" | "271" | "272" | "273" | "274" | "275" | "276" | "277" | "278" | "279" | "280" | "281" | "282" | "283" | "284" | "285" | "286" | "287" | "288" | "289" | "290" | "291" | "292" | "293" | "294" | "295" | "296" | "297" | "298" | "299" | "300" | "301" | "302" | "303" | "304" | "305" | "306" | "307" | "308" | "309" | "310" | "311" | "312" | "313" | "314" | "315" | "316" | "317" | "318" | "319" | "320" | "321" | "322" | "323" | "324" | "325" | "326" | "327" | "328" | "329" | "330" | "331" | "332" | "333" | "334" | "335" | "336" | "337" | "338" | "339" | "340" | "341" | "342" | "343" | "344" | "345" | "346" | "347" | "348" | "349" | "350" | "351" | "352" | "353" | "354" | "355" | "356" | "357" | "358" | "359" | "360" | "361" | "362" | "363" | "364" | "365" | "366" | "367" | "368" | "369" | "370" | "371" | "372" | "373" | "374" | "375" | "376" | "377" | "378" | "379" | "380" | "381" | "382" | "383" | "384" | "385" | "386" | "387" | "388" | "389" | "390" | "391" | "392" | "393" | "394" | "395" | "396" | "397" | "398" | "399" | "400" | "401" | "402" | "403" | "404" | "405" | "406" | "407" | "408" | "409" | "410" | "411" | "412" | "413" | "414" | "415" | "416" | "417" | "418" | "419" | "420" | "421" | "422" | "423" | "424" | "425" | "426" | "427" | "428" | "429" | "430" | "431" | "432" | "433" | "434" | "435" | "436" | "437" | "438" | "439" | "440" | "441" | "442" | "443" | "444" | "445" | "446" | "447" | "448" | "449" | "450" | "451" | "452" | "453" | "454" | "455" | "456" | "457" | "458" | "459" | "460" | "461" | "462" | "463" | "464" | "465" | "466" | "467" | "468" | "469" | "470" | "471" | "472" | "473" | "474" | "475" | "476" | "477" | "478" | "479" | "480" | "481" | "482" | "483" | "484" | "485" | "486" | "487" | "488" | "489" | "490" | "491" | "492" | "493" | "494" | "495" | "496" | "497" | "498" | "499" | "500" | "501" | "502" | "503" | "504" | "505" | "506" | "507" | "508" | "509" | "510" | "511" | "512" | "513" | "514" | "515" | "516" | "517" | "518" | "519" | "520" | "521" | "522" | "523" | "524" | "525" | "526" | "527" | "528" | "529" | "530" | "531" | "532" | "533" | "534" | "535" | "536" | "537" | "538" | "539" | "540" | "541" | "542" | "543" | "544" | "545" | "546" | "547" | "548" | "549" | "550" | "551" | "552" | "553" | "554" | "555" | "556" | "557" | "558" | "559" | "560" | "561" | "562" | "563" | "564" | "565" | "566" | "567" | "568" | "569" | "570" | "571" | "572" | "573" | "574" | "575" | "576" | "577" | "578" | "579" | "580" | "581" | "582" | "583" | "584" | "585" | "586" | "587" | "588" | "589" | "590" | "591" | "592" | "593" | "594" | "595" | "596" | "597" | "598" | "599" | "600" | "601" | "602" | "603" | "604" | "605" | "606" | "607" | "608" | "609" | "610" | "611" | "612" | "613" | "614" | "615" | "616" | "617" | "618" | "619" | "620" | "621" | "622" | "623" | "624" | "625" | "626" | "627" | "628" | "629" | "630" | "631" | "632" | "633" | "634" | "635" | "636" | "637" | "638" | "639" | "640" | "641" | "642" | "643" | "644" | "645" | "646" | "647" | "648" | "649" | "650" | "651" | "652" | "653" | "654" | "655" | "656" | "657" | "658" | "659" | "660" | "661" | "662" | "663" | "664" | "665" | "666" | "667" | "668" | "669" | "670" | "671" | "672" | "673" | "674" | "675" | "676" | "677" | "678" | "679" | "680" | "681" | "682" | "683" | "684" | "685" | "686" | "687" | "688" | "689" | "690" | "691" | "692" | "693" | "694" | "695" | "696" | "697" | "698" | "699" | "700" | "701" | "702" | "703" | "704" | "705" | "706" | "707" | "708" | "709" | "710" | "711" | "712" | "713" | "714" | "715" | "716" | "717" | "718" | "719" | "720" | "721" | "722" | "723" | "724" | "725" | "726" | "727" | "728" | "729" | "730" | "731" | "732" | "733" | "734" | "735" | "736" | "737" | "738" | "739" | "740" | "741" | "742" | "743" | "744" | "745" | "746" | "747" | "748" | "749" | "750" | "751" | "752" | "753" | "754" | "755" | "756" | "757" | "758" | "759" | "760" | "761" | "762" | "763" | "764" | "765" | "766" | "767" | "768" | "769" | "770" | "771" | "772" | "773" | "774" | "775" | "776" | "777" | "778" | "779" | "780" | "781" | "782" | "783" | "784" | "785" | "786" | "787" | "788" | "789" | "790" | "791" | "792" | "793" | "794" | "795" | "796" | "797" | "798" | "799" | "800" | "801" | "802" | "803" | "804" | "805" | "806" | "807" | "808" | "809" | "810" | "811" | "812" | "813" | "814" | "815" | "816" | "817" | "818" | "819" | "820" | "821" | "822" | "823" | "824" | "825" | "826" | "827" | "828" | "829" | "830" | "831" | "832" | "833" | "834" | "835" | "836" | "837" | "838" | "839" | "840" | "841" | "842" | "843" | "844" | "845" | "846" | "847" | "848" | "849" | "850" | "851" | "852" | "853" | "854" | "855" | "856" | "857" | "858" | "859" | "860" | "861" | "862" | "863" | "864" | "865" | "866" | "867" | "868" | "869" | "870" | "871" | "872" | "873" | "874" | "875" | "876" | "877" | "878" | "879" | "880" | "881" | "882" | "883" | "884" | "885" | "886" | "887" | "888" | "889" | "890" | "891" | "892" | "893" | "894" | "895" | "896" | "897" | "898" | "899" | "900" | "901" | "902" | "903" | "904" | "905" | "906" | "907" | "908" | "909" | "910" | "911" | "912" | "913" | "914" | "915" | "916" | "917" | "918" | "919" | "920" | "921" | "922" | "923" | "924" | "925" | "926" | "927" | "928" | "929" | "930" | "931" | "932" | "933" | "934" | "935" | "936" | "937" | "938" | "939" | "940" | "941" | "942" | "943" | "944" | "945" | "946" | "947" | "948" | "949" | "950" | "951" | "952" | "953" | "954" | "955" | "956" | "957" | "958" | "959" | "960" | "961" | "962" | "963" | "964" | "965" | "966" | "967" | "968" | "969" | "970" | "971" | "972" | "973" | "974" | "975" | "976" | "977" | "978" | "979" | "980" | "981" | "982" | "983" | "984" | "985" | "986" | "987" | "988" | "989" | "990" | "991" | "992" | "993" | "994" | "995" | "996" | "997" | "998" | "999" + +// Over a hundred nested instantiations, half of which already happened for +// another statement. +type Deep = N["length"] extends 60 ? never : Deep<[...N, 0]> | N["length"]; +>Deep : Deep + +type DeepTail = Deep<[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]>; +>DeepTail : 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 + +type DeepAll = Deep<[]>; +>DeepAll : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 + diff --git a/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.symbols b/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.symbols new file mode 100644 index 0000000000000..50e733d8606c1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.symbols @@ -0,0 +1,53 @@ +//// [tests/cases/compiler/relationDeeplyNestedCheckOrder.ts] //// + +=== relationDeeplyNestedCheckOrder.ts === +// Relating 'B<{ a: string }>' to 'B<{ a: "lit" }>' eventually relates 'string' +// to '"lit"' through 'm0.m1.a.m0.m1'. Relating the 'A' instantiations first +// reaches the same comparison only after giving up on deeply nested types, +// which must not make relating the 'B' instantiations succeed afterwards. + +type A = { m0: (x: B) => void; m1: { [K in keyof T]: B } }; +>A : Symbol(A, Decl(relationDeeplyNestedCheckOrder.ts, 0, 0)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 5, 7)) +>m0 : Symbol(m0, Decl(relationDeeplyNestedCheckOrder.ts, 5, 13)) +>x : Symbol(x, Decl(relationDeeplyNestedCheckOrder.ts, 5, 19)) +>B : Symbol(B, Decl(relationDeeplyNestedCheckOrder.ts, 5, 71)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 5, 7)) +>m1 : Symbol(m1, Decl(relationDeeplyNestedCheckOrder.ts, 5, 36)) +>K : Symbol(K, Decl(relationDeeplyNestedCheckOrder.ts, 5, 44)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 5, 7)) +>B : Symbol(B, Decl(relationDeeplyNestedCheckOrder.ts, 5, 71)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 5, 7)) +>K : Symbol(K, Decl(relationDeeplyNestedCheckOrder.ts, 5, 44)) + +type B = { m0: A }; +>B : Symbol(B, Decl(relationDeeplyNestedCheckOrder.ts, 5, 71)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 6, 7)) +>m0 : Symbol(m0, Decl(relationDeeplyNestedCheckOrder.ts, 6, 13)) +>A : Symbol(A, Decl(relationDeeplyNestedCheckOrder.ts, 0, 0)) +>T : Symbol(T, Decl(relationDeeplyNestedCheckOrder.ts, 6, 7)) + +declare let a1: A<{ a: string }>, a2: A<{ a: "lit" }>; +>a1 : Symbol(a1, Decl(relationDeeplyNestedCheckOrder.ts, 8, 11)) +>A : Symbol(A, Decl(relationDeeplyNestedCheckOrder.ts, 0, 0)) +>a : Symbol(a, Decl(relationDeeplyNestedCheckOrder.ts, 8, 19)) +>a2 : Symbol(a2, Decl(relationDeeplyNestedCheckOrder.ts, 8, 33)) +>A : Symbol(A, Decl(relationDeeplyNestedCheckOrder.ts, 0, 0)) +>a : Symbol(a, Decl(relationDeeplyNestedCheckOrder.ts, 8, 41)) + +declare let b1: B<{ a: string }>, b2: B<{ a: "lit" }>; +>b1 : Symbol(b1, Decl(relationDeeplyNestedCheckOrder.ts, 9, 11)) +>B : Symbol(B, Decl(relationDeeplyNestedCheckOrder.ts, 5, 71)) +>a : Symbol(a, Decl(relationDeeplyNestedCheckOrder.ts, 9, 19)) +>b2 : Symbol(b2, Decl(relationDeeplyNestedCheckOrder.ts, 9, 33)) +>B : Symbol(B, Decl(relationDeeplyNestedCheckOrder.ts, 5, 71)) +>a : Symbol(a, Decl(relationDeeplyNestedCheckOrder.ts, 9, 41)) + +a2 = a1; +>a2 : Symbol(a2, Decl(relationDeeplyNestedCheckOrder.ts, 8, 33)) +>a1 : Symbol(a1, Decl(relationDeeplyNestedCheckOrder.ts, 8, 11)) + +b2 = b1; // Error +>b2 : Symbol(b2, Decl(relationDeeplyNestedCheckOrder.ts, 9, 33)) +>b1 : Symbol(b1, Decl(relationDeeplyNestedCheckOrder.ts, 9, 11)) + diff --git a/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.types b/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.types new file mode 100644 index 0000000000000..a7755fb5d5533 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/relationDeeplyNestedCheckOrder.types @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/relationDeeplyNestedCheckOrder.ts] //// + +=== relationDeeplyNestedCheckOrder.ts === +// Relating 'B<{ a: string }>' to 'B<{ a: "lit" }>' eventually relates 'string' +// to '"lit"' through 'm0.m1.a.m0.m1'. Relating the 'A' instantiations first +// reaches the same comparison only after giving up on deeply nested types, +// which must not make relating the 'B' instantiations succeed afterwards. + +type A = { m0: (x: B) => void; m1: { [K in keyof T]: B } }; +>A : A +>m0 : (x: B) => void +>x : B +>m1 : { [K in keyof T]: B; } + +type B = { m0: A }; +>B : B +>m0 : A + +declare let a1: A<{ a: string }>, a2: A<{ a: "lit" }>; +>a1 : A<{ a: string; }> +>a : string +>a2 : A<{ a: "lit"; }> +>a : "lit" + +declare let b1: B<{ a: string }>, b2: B<{ a: "lit" }>; +>b1 : B<{ a: string; }> +>a : string +>b2 : B<{ a: "lit"; }> +>a : "lit" + +a2 = a1; +>a2 = a1 : A<{ a: string; }> +>a2 : A<{ a: "lit"; }> +>a1 : A<{ a: string; }> + +b2 = b1; // Error +>b2 = b1 : B<{ a: string; }> +>b2 : B<{ a: "lit"; }> +>b1 : B<{ a: string; }> + diff --git a/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.errors.txt b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.errors.txt new file mode 100644 index 0000000000000..88dee4e5a8f7e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.errors.txt @@ -0,0 +1,31 @@ +relationMaybeCheckOrder.ts(8,32): error TS2322: Type 'B' is not assignable to type 'string | number | symbol'. +relationMaybeCheckOrder.ts(18,11): error TS2322: Type '2' is not assignable to type '1'. + + +==== relationMaybeCheckOrder.ts (2 errors) ==== + // Relating to 'keyof M' rejects keys that relate only by assuming a + // comparison still in progress. Relating 'A' to 'B' assumes only itself + // along 'next', so it completes on its own and must be accepted whether + // or not the call to 'h' related 'A' to 'B' first. + + interface A { next: A; v: "a" } + interface B { next: B; v: string } + type M = { [K in keyof T as B]: 1 }; + ~ +!!! error TS2322: Type 'B' is not assignable to type 'string | number | symbol'. + + declare const a: A; + declare function h(x: B): 1; + declare function h(x: unknown): 2; + + function f() { + function g(x: keyof M): 1; + function g(x: unknown): 2; + function g(x: unknown) { return 1 as any; } + const r: 1 = g(a); + ~ +!!! error TS2322: Type '2' is not assignable to type '1'. + } + + const w: 1 = h(a); + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.symbols b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.symbols new file mode 100644 index 0000000000000..c577599a23c3c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.symbols @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/relationMaybeCheckOrder.ts] //// + +=== relationMaybeCheckOrder.ts === +// Relating to 'keyof M' rejects keys that relate only by assuming a +// comparison still in progress. Relating 'A' to 'B' assumes only itself +// along 'next', so it completes on its own and must be accepted whether +// or not the call to 'h' related 'A' to 'B' first. + +interface A { next: A; v: "a" } +>A : Symbol(A, Decl(relationMaybeCheckOrder.ts, 0, 0)) +>next : Symbol(A.next, Decl(relationMaybeCheckOrder.ts, 5, 13)) +>A : Symbol(A, Decl(relationMaybeCheckOrder.ts, 0, 0)) +>v : Symbol(A.v, Decl(relationMaybeCheckOrder.ts, 5, 22)) + +interface B { next: B; v: string } +>B : Symbol(B, Decl(relationMaybeCheckOrder.ts, 5, 31)) +>next : Symbol(B.next, Decl(relationMaybeCheckOrder.ts, 6, 13)) +>B : Symbol(B, Decl(relationMaybeCheckOrder.ts, 5, 31)) +>v : Symbol(B.v, Decl(relationMaybeCheckOrder.ts, 6, 22)) + +type M = { [K in keyof T as B]: 1 }; +>M : Symbol(M, Decl(relationMaybeCheckOrder.ts, 6, 34)) +>T : Symbol(T, Decl(relationMaybeCheckOrder.ts, 7, 7)) +>K : Symbol(K, Decl(relationMaybeCheckOrder.ts, 7, 15)) +>T : Symbol(T, Decl(relationMaybeCheckOrder.ts, 7, 7)) +>B : Symbol(B, Decl(relationMaybeCheckOrder.ts, 5, 31)) + +declare const a: A; +>a : Symbol(a, Decl(relationMaybeCheckOrder.ts, 9, 13)) +>A : Symbol(A, Decl(relationMaybeCheckOrder.ts, 0, 0)) + +declare function h(x: B): 1; +>h : Symbol(h, Decl(relationMaybeCheckOrder.ts, 9, 19), Decl(relationMaybeCheckOrder.ts, 10, 28)) +>x : Symbol(x, Decl(relationMaybeCheckOrder.ts, 10, 19)) +>B : Symbol(B, Decl(relationMaybeCheckOrder.ts, 5, 31)) + +declare function h(x: unknown): 2; +>h : Symbol(h, Decl(relationMaybeCheckOrder.ts, 9, 19), Decl(relationMaybeCheckOrder.ts, 10, 28)) +>x : Symbol(x, Decl(relationMaybeCheckOrder.ts, 11, 19)) + +function f() { +>f : Symbol(f, Decl(relationMaybeCheckOrder.ts, 11, 34)) +>T : Symbol(T, Decl(relationMaybeCheckOrder.ts, 13, 11)) + + function g(x: keyof M): 1; +>g : Symbol(g, Decl(relationMaybeCheckOrder.ts, 13, 17), Decl(relationMaybeCheckOrder.ts, 14, 33), Decl(relationMaybeCheckOrder.ts, 15, 30)) +>x : Symbol(x, Decl(relationMaybeCheckOrder.ts, 14, 15)) +>M : Symbol(M, Decl(relationMaybeCheckOrder.ts, 6, 34)) +>T : Symbol(T, Decl(relationMaybeCheckOrder.ts, 13, 11)) + + function g(x: unknown): 2; +>g : Symbol(g, Decl(relationMaybeCheckOrder.ts, 13, 17), Decl(relationMaybeCheckOrder.ts, 14, 33), Decl(relationMaybeCheckOrder.ts, 15, 30)) +>x : Symbol(x, Decl(relationMaybeCheckOrder.ts, 15, 15)) + + function g(x: unknown) { return 1 as any; } +>g : Symbol(g, Decl(relationMaybeCheckOrder.ts, 13, 17), Decl(relationMaybeCheckOrder.ts, 14, 33), Decl(relationMaybeCheckOrder.ts, 15, 30)) +>x : Symbol(x, Decl(relationMaybeCheckOrder.ts, 16, 15)) + + const r: 1 = g(a); +>r : Symbol(r, Decl(relationMaybeCheckOrder.ts, 17, 9)) +>g : Symbol(g, Decl(relationMaybeCheckOrder.ts, 13, 17), Decl(relationMaybeCheckOrder.ts, 14, 33), Decl(relationMaybeCheckOrder.ts, 15, 30)) +>a : Symbol(a, Decl(relationMaybeCheckOrder.ts, 9, 13)) +} + +const w: 1 = h(a); +>w : Symbol(w, Decl(relationMaybeCheckOrder.ts, 20, 5)) +>h : Symbol(h, Decl(relationMaybeCheckOrder.ts, 9, 19), Decl(relationMaybeCheckOrder.ts, 10, 28)) +>a : Symbol(a, Decl(relationMaybeCheckOrder.ts, 9, 13)) + diff --git a/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.types b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.types new file mode 100644 index 0000000000000..ecbee15a795d4 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/relationMaybeCheckOrder.types @@ -0,0 +1,60 @@ +//// [tests/cases/compiler/relationMaybeCheckOrder.ts] //// + +=== relationMaybeCheckOrder.ts === +// Relating to 'keyof M' rejects keys that relate only by assuming a +// comparison still in progress. Relating 'A' to 'B' assumes only itself +// along 'next', so it completes on its own and must be accepted whether +// or not the call to 'h' related 'A' to 'B' first. + +interface A { next: A; v: "a" } +>next : A +>v : "a" + +interface B { next: B; v: string } +>next : B +>v : string + +type M = { [K in keyof T as B]: 1 }; +>M : M + +declare const a: A; +>a : A + +declare function h(x: B): 1; +>h : { (x: B): 1; (x: unknown): 2; } +>x : B + +declare function h(x: unknown): 2; +>h : { (x: B): 1; (x: unknown): 2; } +>x : unknown + +function f() { +>f : () => void + + function g(x: keyof M): 1; +>g : { (x: keyof M): 1; (x: unknown): 2; } +>x : keyof M + + function g(x: unknown): 2; +>g : { (x: keyof M): 1; (x: unknown): 2; } +>x : unknown + + function g(x: unknown) { return 1 as any; } +>g : { (x: keyof M): 1; (x: unknown): 2; } +>x : unknown +>1 as any : any +>1 : 1 + + const r: 1 = g(a); +>r : 1 +>g(a) : 2 +>g : { (x: keyof M): 1; (x: unknown): 2; } +>a : A +} + +const w: 1 = h(a); +>w : 1 +>h(a) : 1 +>h : { (x: B): 1; (x: unknown): 2; } +>a : A + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.errors.txt b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.errors.txt new file mode 100644 index 0000000000000..fed3dca53a0ed --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.errors.txt @@ -0,0 +1,25 @@ +first.ts(3,1): error TS2322: Type 'Box' is not assignable to type 'Box'. + Type 'number' is not assignable to type 'string'. + + +==== first.ts (1 errors) ==== + declare let b1: Box; + declare let b2: Box; + b1 = b2; + ~~ +!!! error TS2322: Type 'Box' is not assignable to type 'Box'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + +==== box.ts (0 errors) ==== + declare let a1: Box; + declare let a2: Box; + declare const cond: boolean; + class Box { + value!: T; + m() { + if (cond) return a1; + return a2; + } + } + const r = new Box().m(); + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.js b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.js new file mode 100644 index 0000000000000..1cc3125377745 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/varianceCycleCachedResults.ts] //// + +//// [first.ts] +declare let b1: Box; +declare let b2: Box; +b1 = b2; + +//// [box.ts] +declare let a1: Box; +declare let a2: Box; +declare const cond: boolean; +class Box { + value!: T; + m() { + if (cond) return a1; + return a2; + } +} +const r = new Box().m(); + + +//// [first.js] +"use strict"; +b1 = b2; +//// [box.js] +"use strict"; +class Box { + value; + m() { + if (cond) + return a1; + return a2; + } +} +const r = new Box().m(); diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.symbols b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.symbols new file mode 100644 index 0000000000000..84c44e9268207 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.symbols @@ -0,0 +1,52 @@ +//// [tests/cases/compiler/varianceCycleCachedResults.ts] //// + +=== first.ts === +declare let b1: Box; +>b1 : Symbol(b1, Decl(first.ts, 0, 11)) +>Box : Symbol(Box, Decl(box.ts, 2, 28)) + +declare let b2: Box; +>b2 : Symbol(b2, Decl(first.ts, 1, 11)) +>Box : Symbol(Box, Decl(box.ts, 2, 28)) + +b1 = b2; +>b1 : Symbol(b1, Decl(first.ts, 0, 11)) +>b2 : Symbol(b2, Decl(first.ts, 1, 11)) + +=== box.ts === +declare let a1: Box; +>a1 : Symbol(a1, Decl(box.ts, 0, 11)) +>Box : Symbol(Box, Decl(box.ts, 2, 28)) + +declare let a2: Box; +>a2 : Symbol(a2, Decl(box.ts, 1, 11)) +>Box : Symbol(Box, Decl(box.ts, 2, 28)) + +declare const cond: boolean; +>cond : Symbol(cond, Decl(box.ts, 2, 13)) + +class Box { +>Box : Symbol(Box, Decl(box.ts, 2, 28)) +>T : Symbol(T, Decl(box.ts, 3, 10)) + + value!: T; +>value : Symbol(Box.value, Decl(box.ts, 3, 14)) +>T : Symbol(T, Decl(box.ts, 3, 10)) + + m() { +>m : Symbol(Box.m, Decl(box.ts, 4, 14)) + + if (cond) return a1; +>cond : Symbol(cond, Decl(box.ts, 2, 13)) +>a1 : Symbol(a1, Decl(box.ts, 0, 11)) + + return a2; +>a2 : Symbol(a2, Decl(box.ts, 1, 11)) + } +} +const r = new Box().m(); +>r : Symbol(r, Decl(box.ts, 10, 5)) +>new Box().m : Symbol(Box.m, Decl(box.ts, 4, 14)) +>Box : Symbol(Box, Decl(box.ts, 2, 28)) +>m : Symbol(Box.m, Decl(box.ts, 4, 14)) + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.types b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.types new file mode 100644 index 0000000000000..c5448fc75d3ab --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleCachedResults.types @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/varianceCycleCachedResults.ts] //// + +=== first.ts === +declare let b1: Box; +>b1 : Box + +declare let b2: Box; +>b2 : Box + +b1 = b2; +>b1 = b2 : Box +>b1 : Box +>b2 : Box + +=== box.ts === +declare let a1: Box; +>a1 : Box + +declare let a2: Box; +>a2 : Box + +declare const cond: boolean; +>cond : boolean + +class Box { +>Box : Box + + value!: T; +>value : T + + m() { +>m : () => Box + + if (cond) return a1; +>cond : boolean +>a1 : Box + + return a2; +>a2 : Box + } +} +const r = new Box().m(); +>r : Box +>new Box().m() : Box +>new Box().m : () => Box +>new Box() : Box +>Box : typeof Box +>m : () => Box + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.errors.txt b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.errors.txt new file mode 100644 index 0000000000000..d7a540fb6524a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.errors.txt @@ -0,0 +1,29 @@ +varianceCycleDiscardedDiagnostics.ts(12,5): error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + + +==== varianceCycleDiscardedDiagnostics.ts (1 errors) ==== + // Measuring the variances of Bar resolves the type of Value, which picks an + // overload by relating Foo to Foo while the variances of Foo are + // still a guess. Diagnostics from that attempt must not outlive it. + + interface A { a: string } + interface B { foo: string } + declare function pick(x: Foo): A; + declare function pick(x: object): B; + + class Bar { + x!: T; + Value = pick(new Foo(this)).foo; + ~~~~~ +!!! error TS7022: 'Value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + } + + class Foo { + bar!: Bar; + constructor(bar: Bar) { + this.bar = bar; + } + } + + const v: number = new Bar().Value; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.symbols b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.symbols new file mode 100644 index 0000000000000..3da4d35f8204d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.symbols @@ -0,0 +1,71 @@ +//// [tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts] //// + +=== varianceCycleDiscardedDiagnostics.ts === +// Measuring the variances of Bar resolves the type of Value, which picks an +// overload by relating Foo to Foo while the variances of Foo are +// still a guess. Diagnostics from that attempt must not outlive it. + +interface A { a: string } +>A : Symbol(A, Decl(varianceCycleDiscardedDiagnostics.ts, 0, 0)) +>a : Symbol(A.a, Decl(varianceCycleDiscardedDiagnostics.ts, 4, 13)) + +interface B { foo: string } +>B : Symbol(B, Decl(varianceCycleDiscardedDiagnostics.ts, 4, 25)) +>foo : Symbol(B.foo, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 13)) + +declare function pick(x: Foo): A; +>pick : Symbol(pick, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 27), Decl(varianceCycleDiscardedDiagnostics.ts, 6, 41)) +>x : Symbol(x, Decl(varianceCycleDiscardedDiagnostics.ts, 6, 22)) +>Foo : Symbol(Foo, Decl(varianceCycleDiscardedDiagnostics.ts, 12, 1)) +>A : Symbol(A, Decl(varianceCycleDiscardedDiagnostics.ts, 0, 0)) + +declare function pick(x: object): B; +>pick : Symbol(pick, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 27), Decl(varianceCycleDiscardedDiagnostics.ts, 6, 41)) +>x : Symbol(x, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 22)) +>B : Symbol(B, Decl(varianceCycleDiscardedDiagnostics.ts, 4, 25)) + +class Bar { +>Bar : Symbol(Bar, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 36)) +>T : Symbol(T, Decl(varianceCycleDiscardedDiagnostics.ts, 9, 10)) + + x!: T; +>x : Symbol(Bar.x, Decl(varianceCycleDiscardedDiagnostics.ts, 9, 14)) +>T : Symbol(T, Decl(varianceCycleDiscardedDiagnostics.ts, 9, 10)) + + Value = pick(new Foo(this)).foo; +>Value : Symbol(Bar.Value, Decl(varianceCycleDiscardedDiagnostics.ts, 10, 10)) +>pick(new Foo(this)).foo : Symbol(B.foo, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 13)) +>pick : Symbol(pick, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 27), Decl(varianceCycleDiscardedDiagnostics.ts, 6, 41)) +>Foo : Symbol(Foo, Decl(varianceCycleDiscardedDiagnostics.ts, 12, 1)) +>this : Symbol(Bar, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 36)) +>foo : Symbol(B.foo, Decl(varianceCycleDiscardedDiagnostics.ts, 5, 13)) +} + +class Foo { +>Foo : Symbol(Foo, Decl(varianceCycleDiscardedDiagnostics.ts, 12, 1)) +>T : Symbol(T, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 10)) + + bar!: Bar; +>bar : Symbol(Foo.bar, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 14)) +>Bar : Symbol(Bar, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 36)) +>T : Symbol(T, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 10)) + + constructor(bar: Bar) { +>bar : Symbol(bar, Decl(varianceCycleDiscardedDiagnostics.ts, 16, 16)) +>Bar : Symbol(Bar, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 36)) +>T : Symbol(T, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 10)) + + this.bar = bar; +>this.bar : Symbol(Foo.bar, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 14)) +>this : Symbol(Foo, Decl(varianceCycleDiscardedDiagnostics.ts, 12, 1)) +>bar : Symbol(Foo.bar, Decl(varianceCycleDiscardedDiagnostics.ts, 14, 14)) +>bar : Symbol(bar, Decl(varianceCycleDiscardedDiagnostics.ts, 16, 16)) + } +} + +const v: number = new Bar().Value; +>v : Symbol(v, Decl(varianceCycleDiscardedDiagnostics.ts, 21, 5)) +>new Bar().Value : Symbol(Bar.Value, Decl(varianceCycleDiscardedDiagnostics.ts, 10, 10)) +>Bar : Symbol(Bar, Decl(varianceCycleDiscardedDiagnostics.ts, 7, 36)) +>Value : Symbol(Bar.Value, Decl(varianceCycleDiscardedDiagnostics.ts, 10, 10)) + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.types b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.types new file mode 100644 index 0000000000000..2b4d9d34b6775 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleDiscardedDiagnostics.types @@ -0,0 +1,63 @@ +//// [tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts] //// + +=== varianceCycleDiscardedDiagnostics.ts === +// Measuring the variances of Bar resolves the type of Value, which picks an +// overload by relating Foo to Foo while the variances of Foo are +// still a guess. Diagnostics from that attempt must not outlive it. + +interface A { a: string } +>a : string + +interface B { foo: string } +>foo : string + +declare function pick(x: Foo): A; +>pick : { (x: Foo): A; (x: object): B; } +>x : Foo + +declare function pick(x: object): B; +>pick : { (x: Foo): A; (x: object): B; } +>x : object + +class Bar { +>Bar : Bar + + x!: T; +>x : T + + Value = pick(new Foo(this)).foo; +>Value : any +>pick(new Foo(this)).foo : string +>pick(new Foo(this)) : B +>pick : { (x: Foo): A; (x: object): B; } +>new Foo(this) : Foo +>Foo : typeof Foo +>this : this +>foo : string +} + +class Foo { +>Foo : Foo + + bar!: Bar; +>bar : Bar + + constructor(bar: Bar) { +>bar : Bar + + this.bar = bar; +>this.bar = bar : Bar +>this.bar : Bar +>this : this +>bar : Bar +>bar : Bar + } +} + +const v: number = new Bar().Value; +>v : number +>new Bar().Value : any +>new Bar() : Bar +>Bar : typeof Bar +>Value : any + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.errors.txt b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.errors.txt new file mode 100644 index 0000000000000..3093fe2786a2e --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.errors.txt @@ -0,0 +1,78 @@ +barFirst.ts(9,1): error TS2322: Type 'Bar<"lit">' is not assignable to type 'Bar'. + Type 'string' is not assignable to type '"lit"'. +barFirst.ts(10,1): error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type '"lit"'. +barFirst.ts(11,1): error TS2322: Type 'Foo<"lit">' is not assignable to type 'Foo'. + Types of property 'b' are incompatible. + Type 'Bar>' is not assignable to type 'Bar>'. + Type 'Foo' is not assignable to type 'Foo<"lit">'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type '"lit"'. +fooFirst.ts(8,1): error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type '"lit"'. +fooFirst.ts(9,1): error TS2322: Type 'Foo<"lit">' is not assignable to type 'Foo'. + Types of property 'b' are incompatible. + Type 'Bar>' is not assignable to type 'Bar>'. + Type 'Foo' is not assignable to type 'Foo<"lit">'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type '"lit"'. +fooFirst.ts(11,1): error TS2322: Type 'Bar<"lit">' is not assignable to type 'Bar'. + Type 'string' is not assignable to type '"lit"'. + + +==== fooFirst.ts (3 errors) ==== + export {}; + + interface Foo { x: T; b: Bar> } + interface Bar { f: (u: U) => void; foo: Foo> } + + declare let fs: Foo, fl: Foo<"lit">; + declare let bs: Bar, bl: Bar<"lit">; + fl = fs; // Error + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. +!!! error TS2322: Types of property 'x' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + fs = fl; // Error + ~~ +!!! error TS2322: Type 'Foo<"lit">' is not assignable to type 'Foo'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'Bar>' is not assignable to type 'Bar>'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. +!!! error TS2322: Types of property 'x' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + bl = bs; // Error + bs = bl; // Error + ~~ +!!! error TS2322: Type 'Bar<"lit">' is not assignable to type 'Bar'. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + +==== barFirst.ts (3 errors) ==== + export {}; + + interface Foo { x: T; b: Bar> } + interface Bar { f: (u: U) => void; foo: Foo> } + + declare let fs: Foo, fl: Foo<"lit">; + declare let bs: Bar, bl: Bar<"lit">; + bl = bs; // Error + bs = bl; // Error + ~~ +!!! error TS2322: Type 'Bar<"lit">' is not assignable to type 'Bar'. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + fl = fs; // Error + ~~ +!!! error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. +!!! error TS2322: Types of property 'x' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + fs = fl; // Error + ~~ +!!! error TS2322: Type 'Foo<"lit">' is not assignable to type 'Foo'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'Bar>' is not assignable to type 'Bar>'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Foo<"lit">'. +!!! error TS2322: Types of property 'x' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.symbols b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.symbols new file mode 100644 index 0000000000000..478f02d4a04a7 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.symbols @@ -0,0 +1,106 @@ +//// [tests/cases/compiler/varianceCycleEntryOrder.ts] //// + +=== fooFirst.ts === +export {}; + +interface Foo { x: T; b: Bar> } +>Foo : Symbol(Foo, Decl(fooFirst.ts, 0, 10)) +>T : Symbol(T, Decl(fooFirst.ts, 2, 14)) +>x : Symbol(Foo.x, Decl(fooFirst.ts, 2, 18)) +>T : Symbol(T, Decl(fooFirst.ts, 2, 14)) +>b : Symbol(Foo.b, Decl(fooFirst.ts, 2, 24)) +>Bar : Symbol(Bar, Decl(fooFirst.ts, 2, 41)) +>Foo : Symbol(Foo, Decl(fooFirst.ts, 0, 10)) +>T : Symbol(T, Decl(fooFirst.ts, 2, 14)) + +interface Bar { f: (u: U) => void; foo: Foo> } +>Bar : Symbol(Bar, Decl(fooFirst.ts, 2, 41)) +>U : Symbol(U, Decl(fooFirst.ts, 3, 14)) +>f : Symbol(Bar.f, Decl(fooFirst.ts, 3, 18)) +>u : Symbol(u, Decl(fooFirst.ts, 3, 23)) +>U : Symbol(U, Decl(fooFirst.ts, 3, 14)) +>foo : Symbol(Bar.foo, Decl(fooFirst.ts, 3, 37)) +>Foo : Symbol(Foo, Decl(fooFirst.ts, 0, 10)) +>Bar : Symbol(Bar, Decl(fooFirst.ts, 2, 41)) +>U : Symbol(U, Decl(fooFirst.ts, 3, 14)) + +declare let fs: Foo, fl: Foo<"lit">; +>fs : Symbol(fs, Decl(fooFirst.ts, 5, 11)) +>Foo : Symbol(Foo, Decl(fooFirst.ts, 0, 10)) +>fl : Symbol(fl, Decl(fooFirst.ts, 5, 28)) +>Foo : Symbol(Foo, Decl(fooFirst.ts, 0, 10)) + +declare let bs: Bar, bl: Bar<"lit">; +>bs : Symbol(bs, Decl(fooFirst.ts, 6, 11)) +>Bar : Symbol(Bar, Decl(fooFirst.ts, 2, 41)) +>bl : Symbol(bl, Decl(fooFirst.ts, 6, 28)) +>Bar : Symbol(Bar, Decl(fooFirst.ts, 2, 41)) + +fl = fs; // Error +>fl : Symbol(fl, Decl(fooFirst.ts, 5, 28)) +>fs : Symbol(fs, Decl(fooFirst.ts, 5, 11)) + +fs = fl; // Error +>fs : Symbol(fs, Decl(fooFirst.ts, 5, 11)) +>fl : Symbol(fl, Decl(fooFirst.ts, 5, 28)) + +bl = bs; // Error +>bl : Symbol(bl, Decl(fooFirst.ts, 6, 28)) +>bs : Symbol(bs, Decl(fooFirst.ts, 6, 11)) + +bs = bl; // Error +>bs : Symbol(bs, Decl(fooFirst.ts, 6, 11)) +>bl : Symbol(bl, Decl(fooFirst.ts, 6, 28)) + +=== barFirst.ts === +export {}; + +interface Foo { x: T; b: Bar> } +>Foo : Symbol(Foo, Decl(barFirst.ts, 0, 10)) +>T : Symbol(T, Decl(barFirst.ts, 2, 14)) +>x : Symbol(Foo.x, Decl(barFirst.ts, 2, 18)) +>T : Symbol(T, Decl(barFirst.ts, 2, 14)) +>b : Symbol(Foo.b, Decl(barFirst.ts, 2, 24)) +>Bar : Symbol(Bar, Decl(barFirst.ts, 2, 41)) +>Foo : Symbol(Foo, Decl(barFirst.ts, 0, 10)) +>T : Symbol(T, Decl(barFirst.ts, 2, 14)) + +interface Bar { f: (u: U) => void; foo: Foo> } +>Bar : Symbol(Bar, Decl(barFirst.ts, 2, 41)) +>U : Symbol(U, Decl(barFirst.ts, 3, 14)) +>f : Symbol(Bar.f, Decl(barFirst.ts, 3, 18)) +>u : Symbol(u, Decl(barFirst.ts, 3, 23)) +>U : Symbol(U, Decl(barFirst.ts, 3, 14)) +>foo : Symbol(Bar.foo, Decl(barFirst.ts, 3, 37)) +>Foo : Symbol(Foo, Decl(barFirst.ts, 0, 10)) +>Bar : Symbol(Bar, Decl(barFirst.ts, 2, 41)) +>U : Symbol(U, Decl(barFirst.ts, 3, 14)) + +declare let fs: Foo, fl: Foo<"lit">; +>fs : Symbol(fs, Decl(barFirst.ts, 5, 11)) +>Foo : Symbol(Foo, Decl(barFirst.ts, 0, 10)) +>fl : Symbol(fl, Decl(barFirst.ts, 5, 28)) +>Foo : Symbol(Foo, Decl(barFirst.ts, 0, 10)) + +declare let bs: Bar, bl: Bar<"lit">; +>bs : Symbol(bs, Decl(barFirst.ts, 6, 11)) +>Bar : Symbol(Bar, Decl(barFirst.ts, 2, 41)) +>bl : Symbol(bl, Decl(barFirst.ts, 6, 28)) +>Bar : Symbol(Bar, Decl(barFirst.ts, 2, 41)) + +bl = bs; // Error +>bl : Symbol(bl, Decl(barFirst.ts, 6, 28)) +>bs : Symbol(bs, Decl(barFirst.ts, 6, 11)) + +bs = bl; // Error +>bs : Symbol(bs, Decl(barFirst.ts, 6, 11)) +>bl : Symbol(bl, Decl(barFirst.ts, 6, 28)) + +fl = fs; // Error +>fl : Symbol(fl, Decl(barFirst.ts, 5, 28)) +>fs : Symbol(fs, Decl(barFirst.ts, 5, 11)) + +fs = fl; // Error +>fs : Symbol(fs, Decl(barFirst.ts, 5, 11)) +>fl : Symbol(fl, Decl(barFirst.ts, 5, 28)) + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.types b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.types new file mode 100644 index 0000000000000..3e1522dd51543 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleEntryOrder.types @@ -0,0 +1,82 @@ +//// [tests/cases/compiler/varianceCycleEntryOrder.ts] //// + +=== fooFirst.ts === +export {}; + +interface Foo { x: T; b: Bar> } +>x : T +>b : Bar> + +interface Bar { f: (u: U) => void; foo: Foo> } +>f : (u: U) => void +>u : U +>foo : Foo> + +declare let fs: Foo, fl: Foo<"lit">; +>fs : Foo +>fl : Foo<"lit"> + +declare let bs: Bar, bl: Bar<"lit">; +>bs : Bar +>bl : Bar<"lit"> + +fl = fs; // Error +>fl = fs : Foo +>fl : Foo<"lit"> +>fs : Foo + +fs = fl; // Error +>fs = fl : Foo<"lit"> +>fs : Foo +>fl : Foo<"lit"> + +bl = bs; // Error +>bl = bs : Bar +>bl : Bar<"lit"> +>bs : Bar + +bs = bl; // Error +>bs = bl : Bar<"lit"> +>bs : Bar +>bl : Bar<"lit"> + +=== barFirst.ts === +export {}; + +interface Foo { x: T; b: Bar> } +>x : T +>b : Bar> + +interface Bar { f: (u: U) => void; foo: Foo> } +>f : (u: U) => void +>u : U +>foo : Foo> + +declare let fs: Foo, fl: Foo<"lit">; +>fs : Foo +>fl : Foo<"lit"> + +declare let bs: Bar, bl: Bar<"lit">; +>bs : Bar +>bl : Bar<"lit"> + +bl = bs; // Error +>bl = bs : Bar +>bl : Bar<"lit"> +>bs : Bar + +bs = bl; // Error +>bs = bl : Bar<"lit"> +>bs : Bar +>bl : Bar<"lit"> + +fl = fs; // Error +>fl = fs : Foo +>fl : Foo<"lit"> +>fs : Foo + +fs = fl; // Error +>fs = fl : Foo<"lit"> +>fs : Foo +>fl : Foo<"lit"> + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.errors.txt b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.errors.txt new file mode 100644 index 0000000000000..85a24505357b2 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.errors.txt @@ -0,0 +1,86 @@ +maFirst.ts(8,1): error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. + The types of 'x.p' are incompatible between these types. + Type 'string' is not assignable to type '"lit"'. +maFirst.ts(9,1): error TS2322: Type 'MA<{ p: "lit"; }>' is not assignable to type 'MA<{ p: string; }>'. + Types of property 'b' are incompatible. + Type 'MB>' is not assignable to type 'MB>'. + Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. + The types of 'x.p' are incompatible between these types. + Type 'string' is not assignable to type '"lit"'. +maFirst.ts(11,1): error TS2322: Type 'MB<{ p: "lit"; }>' is not assignable to type 'MB<{ p: string; }>'. + Type '{ p: string; }' is not assignable to type '{ p: "lit"; }'. + Types of property 'p' are incompatible. + Type 'string' is not assignable to type '"lit"'. +mbFirst.ts(9,1): error TS2322: Type 'MB<{ p: "lit"; }>' is not assignable to type 'MB<{ p: string; }>'. + Type '{ p: string; }' is not assignable to type '{ p: "lit"; }'. + Types of property 'p' are incompatible. + Type 'string' is not assignable to type '"lit"'. +mbFirst.ts(10,1): error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. + The types of 'x.p' are incompatible between these types. + Type 'string' is not assignable to type '"lit"'. +mbFirst.ts(11,1): error TS2322: Type 'MA<{ p: "lit"; }>' is not assignable to type 'MA<{ p: string; }>'. + Types of property 'b' are incompatible. + Type 'MB>' is not assignable to type 'MB>'. + Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. + The types of 'x.p' are incompatible between these types. + Type 'string' is not assignable to type '"lit"'. + + +==== maFirst.ts (3 errors) ==== + export {}; + + type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; + type MB = { f: (u: U) => void; a: MA> }; + + declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; + declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; + al = as; + ~~ +!!! error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. +!!! error TS2322: The types of 'x.p' are incompatible between these types. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + as = al; + ~~ +!!! error TS2322: Type 'MA<{ p: "lit"; }>' is not assignable to type 'MA<{ p: string; }>'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'MB>' is not assignable to type 'MB>'. +!!! error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. +!!! error TS2322: The types of 'x.p' are incompatible between these types. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + bl = bs; + bs = bl; + ~~ +!!! error TS2322: Type 'MB<{ p: "lit"; }>' is not assignable to type 'MB<{ p: string; }>'. +!!! error TS2322: Type '{ p: string; }' is not assignable to type '{ p: "lit"; }'. +!!! error TS2322: Types of property 'p' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + +==== mbFirst.ts (3 errors) ==== + export {}; + + type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; + type MB = { f: (u: U) => void; a: MA> }; + + declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; + declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; + bl = bs; + bs = bl; + ~~ +!!! error TS2322: Type 'MB<{ p: "lit"; }>' is not assignable to type 'MB<{ p: string; }>'. +!!! error TS2322: Type '{ p: string; }' is not assignable to type '{ p: "lit"; }'. +!!! error TS2322: Types of property 'p' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + al = as; + ~~ +!!! error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. +!!! error TS2322: The types of 'x.p' are incompatible between these types. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + as = al; + ~~ +!!! error TS2322: Type 'MA<{ p: "lit"; }>' is not assignable to type 'MA<{ p: string; }>'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'MB>' is not assignable to type 'MB>'. +!!! error TS2322: Type 'MA<{ p: string; }>' is not assignable to type 'MA<{ p: "lit"; }>'. +!!! error TS2322: The types of 'x.p' are incompatible between these types. +!!! error TS2322: Type 'string' is not assignable to type '"lit"'. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.symbols b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.symbols new file mode 100644 index 0000000000000..6859a8dde928b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.symbols @@ -0,0 +1,120 @@ +//// [tests/cases/compiler/varianceCycleStructuralFallback.ts] //// + +=== maFirst.ts === +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +>MA : Symbol(MA, Decl(maFirst.ts, 0, 10)) +>T : Symbol(T, Decl(maFirst.ts, 2, 8)) +>x : Symbol(x, Decl(maFirst.ts, 2, 14)) +>K : Symbol(K, Decl(maFirst.ts, 2, 21)) +>T : Symbol(T, Decl(maFirst.ts, 2, 8)) +>T : Symbol(T, Decl(maFirst.ts, 2, 8)) +>K : Symbol(K, Decl(maFirst.ts, 2, 21)) +>b : Symbol(b, Decl(maFirst.ts, 2, 45)) +>MB : Symbol(MB, Decl(maFirst.ts, 2, 61)) +>MA : Symbol(MA, Decl(maFirst.ts, 0, 10)) +>T : Symbol(T, Decl(maFirst.ts, 2, 8)) + +type MB = { f: (u: U) => void; a: MA> }; +>MB : Symbol(MB, Decl(maFirst.ts, 2, 61)) +>U : Symbol(U, Decl(maFirst.ts, 3, 8)) +>f : Symbol(f, Decl(maFirst.ts, 3, 14)) +>u : Symbol(u, Decl(maFirst.ts, 3, 19)) +>U : Symbol(U, Decl(maFirst.ts, 3, 8)) +>a : Symbol(a, Decl(maFirst.ts, 3, 33)) +>MA : Symbol(MA, Decl(maFirst.ts, 0, 10)) +>MB : Symbol(MB, Decl(maFirst.ts, 2, 61)) +>U : Symbol(U, Decl(maFirst.ts, 3, 8)) + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +>as : Symbol(as, Decl(maFirst.ts, 5, 11)) +>MA : Symbol(MA, Decl(maFirst.ts, 0, 10)) +>p : Symbol(p, Decl(maFirst.ts, 5, 20)) +>al : Symbol(al, Decl(maFirst.ts, 5, 34)) +>MA : Symbol(MA, Decl(maFirst.ts, 0, 10)) +>p : Symbol(p, Decl(maFirst.ts, 5, 43)) + +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +>bs : Symbol(bs, Decl(maFirst.ts, 6, 11)) +>MB : Symbol(MB, Decl(maFirst.ts, 2, 61)) +>p : Symbol(p, Decl(maFirst.ts, 6, 20)) +>bl : Symbol(bl, Decl(maFirst.ts, 6, 34)) +>MB : Symbol(MB, Decl(maFirst.ts, 2, 61)) +>p : Symbol(p, Decl(maFirst.ts, 6, 43)) + +al = as; +>al : Symbol(al, Decl(maFirst.ts, 5, 34)) +>as : Symbol(as, Decl(maFirst.ts, 5, 11)) + +as = al; +>as : Symbol(as, Decl(maFirst.ts, 5, 11)) +>al : Symbol(al, Decl(maFirst.ts, 5, 34)) + +bl = bs; +>bl : Symbol(bl, Decl(maFirst.ts, 6, 34)) +>bs : Symbol(bs, Decl(maFirst.ts, 6, 11)) + +bs = bl; +>bs : Symbol(bs, Decl(maFirst.ts, 6, 11)) +>bl : Symbol(bl, Decl(maFirst.ts, 6, 34)) + +=== mbFirst.ts === +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +>MA : Symbol(MA, Decl(mbFirst.ts, 0, 10)) +>T : Symbol(T, Decl(mbFirst.ts, 2, 8)) +>x : Symbol(x, Decl(mbFirst.ts, 2, 14)) +>K : Symbol(K, Decl(mbFirst.ts, 2, 21)) +>T : Symbol(T, Decl(mbFirst.ts, 2, 8)) +>T : Symbol(T, Decl(mbFirst.ts, 2, 8)) +>K : Symbol(K, Decl(mbFirst.ts, 2, 21)) +>b : Symbol(b, Decl(mbFirst.ts, 2, 45)) +>MB : Symbol(MB, Decl(mbFirst.ts, 2, 61)) +>MA : Symbol(MA, Decl(mbFirst.ts, 0, 10)) +>T : Symbol(T, Decl(mbFirst.ts, 2, 8)) + +type MB = { f: (u: U) => void; a: MA> }; +>MB : Symbol(MB, Decl(mbFirst.ts, 2, 61)) +>U : Symbol(U, Decl(mbFirst.ts, 3, 8)) +>f : Symbol(f, Decl(mbFirst.ts, 3, 14)) +>u : Symbol(u, Decl(mbFirst.ts, 3, 19)) +>U : Symbol(U, Decl(mbFirst.ts, 3, 8)) +>a : Symbol(a, Decl(mbFirst.ts, 3, 33)) +>MA : Symbol(MA, Decl(mbFirst.ts, 0, 10)) +>MB : Symbol(MB, Decl(mbFirst.ts, 2, 61)) +>U : Symbol(U, Decl(mbFirst.ts, 3, 8)) + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +>as : Symbol(as, Decl(mbFirst.ts, 5, 11)) +>MA : Symbol(MA, Decl(mbFirst.ts, 0, 10)) +>p : Symbol(p, Decl(mbFirst.ts, 5, 20)) +>al : Symbol(al, Decl(mbFirst.ts, 5, 34)) +>MA : Symbol(MA, Decl(mbFirst.ts, 0, 10)) +>p : Symbol(p, Decl(mbFirst.ts, 5, 43)) + +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +>bs : Symbol(bs, Decl(mbFirst.ts, 6, 11)) +>MB : Symbol(MB, Decl(mbFirst.ts, 2, 61)) +>p : Symbol(p, Decl(mbFirst.ts, 6, 20)) +>bl : Symbol(bl, Decl(mbFirst.ts, 6, 34)) +>MB : Symbol(MB, Decl(mbFirst.ts, 2, 61)) +>p : Symbol(p, Decl(mbFirst.ts, 6, 43)) + +bl = bs; +>bl : Symbol(bl, Decl(mbFirst.ts, 6, 34)) +>bs : Symbol(bs, Decl(mbFirst.ts, 6, 11)) + +bs = bl; +>bs : Symbol(bs, Decl(mbFirst.ts, 6, 11)) +>bl : Symbol(bl, Decl(mbFirst.ts, 6, 34)) + +al = as; +>al : Symbol(al, Decl(mbFirst.ts, 5, 34)) +>as : Symbol(as, Decl(mbFirst.ts, 5, 11)) + +as = al; +>as : Symbol(as, Decl(mbFirst.ts, 5, 11)) +>al : Symbol(al, Decl(mbFirst.ts, 5, 34)) + diff --git a/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.types b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.types new file mode 100644 index 0000000000000..e40fcb80e2fea --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceCycleStructuralFallback.types @@ -0,0 +1,94 @@ +//// [tests/cases/compiler/varianceCycleStructuralFallback.ts] //// + +=== maFirst.ts === +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +>MA : MA +>x : { [K in keyof T]-?: T[K]; } +>b : MB> + +type MB = { f: (u: U) => void; a: MA> }; +>MB : MB +>f : (u: U) => void +>u : U +>a : MA> + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +>as : MA<{ p: string; }> +>p : string +>al : MA<{ p: "lit"; }> +>p : "lit" + +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +>bs : MB<{ p: string; }> +>p : string +>bl : MB<{ p: "lit"; }> +>p : "lit" + +al = as; +>al = as : MA<{ p: string; }> +>al : MA<{ p: "lit"; }> +>as : MA<{ p: string; }> + +as = al; +>as = al : MA<{ p: "lit"; }> +>as : MA<{ p: string; }> +>al : MA<{ p: "lit"; }> + +bl = bs; +>bl = bs : MB<{ p: string; }> +>bl : MB<{ p: "lit"; }> +>bs : MB<{ p: string; }> + +bs = bl; +>bs = bl : MB<{ p: "lit"; }> +>bs : MB<{ p: string; }> +>bl : MB<{ p: "lit"; }> + +=== mbFirst.ts === +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +>MA : MA +>x : { [K in keyof T]-?: T[K]; } +>b : MB> + +type MB = { f: (u: U) => void; a: MA> }; +>MB : MB +>f : (u: U) => void +>u : U +>a : MA> + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +>as : MA<{ p: string; }> +>p : string +>al : MA<{ p: "lit"; }> +>p : "lit" + +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +>bs : MB<{ p: string; }> +>p : string +>bl : MB<{ p: "lit"; }> +>p : "lit" + +bl = bs; +>bl = bs : MB<{ p: string; }> +>bl : MB<{ p: "lit"; }> +>bs : MB<{ p: string; }> + +bs = bl; +>bs = bl : MB<{ p: "lit"; }> +>bs : MB<{ p: string; }> +>bl : MB<{ p: "lit"; }> + +al = as; +>al = as : MA<{ p: string; }> +>al : MA<{ p: "lit"; }> +>as : MA<{ p: string; }> + +as = al; +>as = al : MA<{ p: "lit"; }> +>as : MA<{ p: string; }> +>al : MA<{ p: "lit"; }> + diff --git a/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.errors.txt b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.errors.txt new file mode 100644 index 0000000000000..d3d975854426a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.errors.txt @@ -0,0 +1,63 @@ +varianceMeasuredWithinCircularity.ts(24,5): error TS2322: Type 'Selection' is not assignable to type 'Selection'. + Types of property 'join' are incompatible. + Type '(enter: string | ((elem: Selection) => Selection | TransitionLike)) => Selection' is not assignable to type '(enter: string | ((elem: Selection) => Selection | TransitionLike)) => Selection'. + Types of parameters 'enter' and 'enter' are incompatible. + Type 'string | ((elem: Selection) => Selection | TransitionLike)' is not assignable to type 'string | ((elem: Selection) => Selection | TransitionLike)'. + Type '(elem: Selection) => Selection | TransitionLike' is not assignable to type 'string | ((elem: Selection) => Selection | TransitionLike)'. + Type '(elem: Selection) => Selection | TransitionLike' is not assignable to type '(elem: Selection) => Selection | TransitionLike'. + Type 'Selection | TransitionLike' is not assignable to type 'Selection | TransitionLike'. + Type 'Selection' is not assignable to type 'Selection | TransitionLike'. + Type 'Selection' is not assignable to type 'Selection'. + Types of property 'data' are incompatible. + Type '(key: (parent: Base) => string) => Selection' is not assignable to type '(key: (parent: Derived) => string) => Selection'. + Types of parameters 'key' and 'key' are incompatible. + Types of parameters 'parent' and 'parent' are incompatible. + Property 'derived' is missing in type 'Base' but required in type 'Derived'. + + +==== varianceMeasuredWithinCircularity.ts (1 errors) ==== + // The variances of Selection and TransitionLike depend on each other. + // The callback of `data` requires Selection to be covariant in P, while + // `join` passes Selection to a callback, which then requires it to + // be contravariant in P, so Selection is invariant in P. TransitionLike + // reaches P of a Selection through `selection().children()`, so it is + // invariant in G. Both must hold whichever variance is measured first. + + export {}; + + interface Base { base: string } + interface Derived extends Base { derived: string } + + interface Selection { + data(key: (parent: P) => string): Selection; + join(enter: string | ((elem: Selection) => Selection | TransitionLike)): Selection; + children(): Selection; + } + + interface TransitionLike { + selection(): Selection; + } + + declare let s1: Selection; + let s2: Selection = s1; + ~~ +!!! error TS2322: Type 'Selection' is not assignable to type 'Selection'. +!!! error TS2322: Types of property 'join' are incompatible. +!!! error TS2322: Type '(enter: string | ((elem: Selection) => Selection | TransitionLike)) => Selection' is not assignable to type '(enter: string | ((elem: Selection) => Selection | TransitionLike)) => Selection'. +!!! error TS2322: Types of parameters 'enter' and 'enter' are incompatible. +!!! error TS2322: Type 'string | ((elem: Selection) => Selection | TransitionLike)' is not assignable to type 'string | ((elem: Selection) => Selection | TransitionLike)'. +!!! error TS2322: Type '(elem: Selection) => Selection | TransitionLike' is not assignable to type 'string | ((elem: Selection) => Selection | TransitionLike)'. +!!! error TS2322: Type '(elem: Selection) => Selection | TransitionLike' is not assignable to type '(elem: Selection) => Selection | TransitionLike'. +!!! error TS2322: Type 'Selection | TransitionLike' is not assignable to type 'Selection | TransitionLike'. +!!! error TS2322: Type 'Selection' is not assignable to type 'Selection | TransitionLike'. +!!! error TS2322: Type 'Selection' is not assignable to type 'Selection'. +!!! error TS2322: Types of property 'data' are incompatible. +!!! error TS2322: Type '(key: (parent: Base) => string) => Selection' is not assignable to type '(key: (parent: Derived) => string) => Selection'. +!!! error TS2322: Types of parameters 'key' and 'key' are incompatible. +!!! error TS2322: Types of parameters 'parent' and 'parent' are incompatible. +!!! error TS2322: Property 'derived' is missing in type 'Base' but required in type 'Derived'. +!!! related TS2728 varianceMeasuredWithinCircularity.ts:11:34: 'derived' is declared here. + + declare let t1: TransitionLike; + let t2: TransitionLike = t1; + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.symbols b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.symbols new file mode 100644 index 0000000000000..23cef834c47e8 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.symbols @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/varianceMeasuredWithinCircularity.ts] //// + +=== varianceMeasuredWithinCircularity.ts === +// The variances of Selection and TransitionLike depend on each other. +// The callback of `data` requires Selection to be covariant in P, while +// `join` passes Selection to a callback, which then requires it to +// be contravariant in P, so Selection is invariant in P. TransitionLike +// reaches P of a Selection through `selection().children()`, so it is +// invariant in G. Both must hold whichever variance is measured first. + +export {}; + +interface Base { base: string } +>Base : Symbol(Base, Decl(varianceMeasuredWithinCircularity.ts, 7, 10)) +>base : Symbol(Base.base, Decl(varianceMeasuredWithinCircularity.ts, 9, 16)) + +interface Derived extends Base { derived: string } +>Derived : Symbol(Derived, Decl(varianceMeasuredWithinCircularity.ts, 9, 31)) +>Base : Symbol(Base, Decl(varianceMeasuredWithinCircularity.ts, 7, 10)) +>derived : Symbol(Derived.derived, Decl(varianceMeasuredWithinCircularity.ts, 10, 32)) + +interface Selection { +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) + + data(key: (parent: P) => string): Selection; +>data : Symbol(Selection.data, Decl(varianceMeasuredWithinCircularity.ts, 12, 27)) +>key : Symbol(key, Decl(varianceMeasuredWithinCircularity.ts, 13, 9)) +>parent : Symbol(parent, Decl(varianceMeasuredWithinCircularity.ts, 13, 15)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) + + join(enter: string | ((elem: Selection) => Selection | TransitionLike)): Selection; +>join : Symbol(Selection.join, Decl(varianceMeasuredWithinCircularity.ts, 13, 54)) +>enter : Symbol(enter, Decl(varianceMeasuredWithinCircularity.ts, 14, 9)) +>elem : Symbol(elem, Decl(varianceMeasuredWithinCircularity.ts, 14, 27)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) +>TransitionLike : Symbol(TransitionLike, Decl(varianceMeasuredWithinCircularity.ts, 16, 1)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +>P : Symbol(P, Decl(varianceMeasuredWithinCircularity.ts, 12, 22)) + + children(): Selection; +>children : Symbol(Selection.children, Decl(varianceMeasuredWithinCircularity.ts, 14, 108)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 12, 20)) +} + +interface TransitionLike { +>TransitionLike : Symbol(TransitionLike, Decl(varianceMeasuredWithinCircularity.ts, 16, 1)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 18, 25)) + + selection(): Selection; +>selection : Symbol(TransitionLike.selection, Decl(varianceMeasuredWithinCircularity.ts, 18, 29)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>G : Symbol(G, Decl(varianceMeasuredWithinCircularity.ts, 18, 25)) +} + +declare let s1: Selection; +>s1 : Symbol(s1, Decl(varianceMeasuredWithinCircularity.ts, 22, 11)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>Derived : Symbol(Derived, Decl(varianceMeasuredWithinCircularity.ts, 9, 31)) + +let s2: Selection = s1; +>s2 : Symbol(s2, Decl(varianceMeasuredWithinCircularity.ts, 23, 3)) +>Selection : Symbol(Selection, Decl(varianceMeasuredWithinCircularity.ts, 10, 50)) +>Base : Symbol(Base, Decl(varianceMeasuredWithinCircularity.ts, 7, 10)) +>s1 : Symbol(s1, Decl(varianceMeasuredWithinCircularity.ts, 22, 11)) + +declare let t1: TransitionLike; +>t1 : Symbol(t1, Decl(varianceMeasuredWithinCircularity.ts, 25, 11)) +>TransitionLike : Symbol(TransitionLike, Decl(varianceMeasuredWithinCircularity.ts, 16, 1)) +>Derived : Symbol(Derived, Decl(varianceMeasuredWithinCircularity.ts, 9, 31)) + +let t2: TransitionLike = t1; +>t2 : Symbol(t2, Decl(varianceMeasuredWithinCircularity.ts, 26, 3)) +>TransitionLike : Symbol(TransitionLike, Decl(varianceMeasuredWithinCircularity.ts, 16, 1)) +>Base : Symbol(Base, Decl(varianceMeasuredWithinCircularity.ts, 7, 10)) +>t1 : Symbol(t1, Decl(varianceMeasuredWithinCircularity.ts, 25, 11)) + diff --git a/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.types b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.types new file mode 100644 index 0000000000000..e6075d898565c --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/varianceMeasuredWithinCircularity.types @@ -0,0 +1,52 @@ +//// [tests/cases/compiler/varianceMeasuredWithinCircularity.ts] //// + +=== varianceMeasuredWithinCircularity.ts === +// The variances of Selection and TransitionLike depend on each other. +// The callback of `data` requires Selection to be covariant in P, while +// `join` passes Selection to a callback, which then requires it to +// be contravariant in P, so Selection is invariant in P. TransitionLike +// reaches P of a Selection through `selection().children()`, so it is +// invariant in G. Both must hold whichever variance is measured first. + +export {}; + +interface Base { base: string } +>base : string + +interface Derived extends Base { derived: string } +>derived : string + +interface Selection { + data(key: (parent: P) => string): Selection; +>data : (key: (parent: P) => string) => Selection +>key : (parent: P) => string +>parent : P + + join(enter: string | ((elem: Selection) => Selection | TransitionLike)): Selection; +>join : (enter: string | ((elem: Selection) => Selection | TransitionLike)) => Selection +>enter : string | ((elem: Selection) => Selection | TransitionLike) +>elem : Selection + + children(): Selection; +>children : () => Selection +} + +interface TransitionLike { + selection(): Selection; +>selection : () => Selection +} + +declare let s1: Selection; +>s1 : Selection + +let s2: Selection = s1; +>s2 : Selection +>s1 : Selection + +declare let t1: TransitionLike; +>t1 : TransitionLike + +let t2: TransitionLike = t1; +>t2 : TransitionLike +>t1 : TransitionLike + diff --git a/tsc/testdata/tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts b/tsc/testdata/tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts new file mode 100644 index 0000000000000..4d185d6668c8a --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/contextualCheckReentryFromOuterTypeParameters.ts @@ -0,0 +1,17 @@ +// @strict: true +// @noEmit: true + +interface Argv { + command(builder: (args: Argv) => Argv, handler: (args: Arguments) => void): Argv; + option(key: K, options: O): Argv<{ [key in K]: O } & Check>; +} +type Arguments = { [key in keyof T]: T[key] } & { [key: string]: unknown }; +type Check = O extends {} ? {} : {}; +declare const yargs: Argv; + +yargs.command( + (yargs) => yargs.option("a", { type: "string" }), + (argv) => { + const a: { type: string } = argv.a; + }, +); diff --git a/tsc/testdata/tests/cases/compiler/deferredTypeReferenceCycleRollback.ts b/tsc/testdata/tests/cases/compiler/deferredTypeReferenceCycleRollback.ts new file mode 100644 index 0000000000000..a33318012116f --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/deferredTypeReferenceCycleRollback.ts @@ -0,0 +1,20 @@ +// @strict: true +// @noEmit: true + +// A cycle rollback used to reset the type of the Array> +// node while the deferred reference identified by that node survived, +// which crashed a later instantiation of it. + +declare function declare(): void; + +interface PluginObj { + visitor: Visit; +} +type Visit = VisitFn | VisitObj; +type VisitFn = (path: NodePath

) => void; +interface VisitObj {} +declare class NodePath { + parentPath: NodePath>; + get: Get; +} +type Get = T extends Array ? Array> : never; diff --git a/tsc/testdata/tests/cases/compiler/instantiationLimitsCheckOrder.ts b/tsc/testdata/tests/cases/compiler/instantiationLimitsCheckOrder.ts new file mode 100644 index 0000000000000..2047e52a8329c --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/instantiationLimitsCheckOrder.ts @@ -0,0 +1,25 @@ +// @noEmit: true + +// Instantiation limits must not depend on what was instantiated before. +// This holds for the depth limit, but not yet for the limit on the number +// of instantiations, which Wide2All only reaches if Wide2Tail was not +// checked first. + +type D = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; +type K = `${D}${D}${D}`; + +// Over five million instantiations for one statement. +type Wide = N["length"] extends 6 ? I : { [J in K]: Wide<[...N, 0], [J, I][0]> }[K]; +type WideAll = Wide<[], "">; + +// The same, but half of the instantiations already happened for another +// statement. +type Wide2 = N["length"] extends 6 ? I : { [J in K]: Wide2<[...N, 0], [J, I][0]> }[K]; +type Wide2Tail = Wide2<[0, 0, 0], "">; +type Wide2All = Wide2<[], "">; + +// Over a hundred nested instantiations, half of which already happened for +// another statement. +type Deep = N["length"] extends 60 ? never : Deep<[...N, 0]> | N["length"]; +type DeepTail = Deep<[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]>; +type DeepAll = Deep<[]>; diff --git a/tsc/testdata/tests/cases/compiler/relationDeeplyNestedCheckOrder.ts b/tsc/testdata/tests/cases/compiler/relationDeeplyNestedCheckOrder.ts new file mode 100644 index 0000000000000..a085da345dfcb --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/relationDeeplyNestedCheckOrder.ts @@ -0,0 +1,16 @@ +// @strict: true +// @noEmit: true + +// Relating 'B<{ a: string }>' to 'B<{ a: "lit" }>' eventually relates 'string' +// to '"lit"' through 'm0.m1.a.m0.m1'. Relating the 'A' instantiations first +// reaches the same comparison only after giving up on deeply nested types, +// which must not make relating the 'B' instantiations succeed afterwards. + +type A = { m0: (x: B) => void; m1: { [K in keyof T]: B } }; +type B = { m0: A }; + +declare let a1: A<{ a: string }>, a2: A<{ a: "lit" }>; +declare let b1: B<{ a: string }>, b2: B<{ a: "lit" }>; + +a2 = a1; +b2 = b1; // Error diff --git a/tsc/testdata/tests/cases/compiler/relationMaybeCheckOrder.ts b/tsc/testdata/tests/cases/compiler/relationMaybeCheckOrder.ts new file mode 100644 index 0000000000000..b56c53b300a7a --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/relationMaybeCheckOrder.ts @@ -0,0 +1,24 @@ +// @strict: true +// @noEmit: true + +// Relating to 'keyof M' rejects keys that relate only by assuming a +// comparison still in progress. Relating 'A' to 'B' assumes only itself +// along 'next', so it completes on its own and must be accepted whether +// or not the call to 'h' related 'A' to 'B' first. + +interface A { next: A; v: "a" } +interface B { next: B; v: string } +type M = { [K in keyof T as B]: 1 }; + +declare const a: A; +declare function h(x: B): 1; +declare function h(x: unknown): 2; + +function f() { + function g(x: keyof M): 1; + function g(x: unknown): 2; + function g(x: unknown) { return 1 as any; } + const r: 1 = g(a); +} + +const w: 1 = h(a); diff --git a/tsc/testdata/tests/cases/compiler/varianceCycleCachedResults.ts b/tsc/testdata/tests/cases/compiler/varianceCycleCachedResults.ts new file mode 100644 index 0000000000000..d8d751ee1e7bc --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/varianceCycleCachedResults.ts @@ -0,0 +1,24 @@ +// @strict: true + +// Relating 'Box' to 'Box' measures the variances of 'Box', which +// resolves the return type of 'm', which relates 'Box' to 'Box' +// while those variances are incomplete. Results computed meanwhile must not be +// kept, so 'm' returns both types. + +// @filename: first.ts +declare let b1: Box; +declare let b2: Box; +b1 = b2; + +// @filename: box.ts +declare let a1: Box; +declare let a2: Box; +declare const cond: boolean; +class Box { + value!: T; + m() { + if (cond) return a1; + return a2; + } +} +const r = new Box().m(); diff --git a/tsc/testdata/tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts b/tsc/testdata/tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts new file mode 100644 index 0000000000000..c610fbca080d7 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/varianceCycleDiscardedDiagnostics.ts @@ -0,0 +1,26 @@ +// @strict: true +// @target: es2022 +// @noEmit: true + +// Measuring the variances of Bar resolves the type of Value, which picks an +// overload by relating Foo to Foo while the variances of Foo are +// still a guess. Diagnostics from that attempt must not outlive it. + +interface A { a: string } +interface B { foo: string } +declare function pick(x: Foo): A; +declare function pick(x: object): B; + +class Bar { + x!: T; + Value = pick(new Foo(this)).foo; +} + +class Foo { + bar!: Bar; + constructor(bar: Bar) { + this.bar = bar; + } +} + +const v: number = new Bar().Value; diff --git a/tsc/testdata/tests/cases/compiler/varianceCycleEntryOrder.ts b/tsc/testdata/tests/cases/compiler/varianceCycleEntryOrder.ts new file mode 100644 index 0000000000000..e7d881c167dcf --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/varianceCycleEntryOrder.ts @@ -0,0 +1,32 @@ +// @strict: true +// @noEmit: true + +// Foo and Bar are both invariant: Foo through x and the contravariant +// use of Foo in Bar, and Bar through f and the invariant Foo>. +// Their variances should not depend on which is measured first. + +// @filename: fooFirst.ts +export {}; + +interface Foo { x: T; b: Bar> } +interface Bar { f: (u: U) => void; foo: Foo> } + +declare let fs: Foo, fl: Foo<"lit">; +declare let bs: Bar, bl: Bar<"lit">; +fl = fs; // Error +fs = fl; // Error +bl = bs; // Error +bs = bl; // Error + +// @filename: barFirst.ts +export {}; + +interface Foo { x: T; b: Bar> } +interface Bar { f: (u: U) => void; foo: Foo> } + +declare let fs: Foo, fl: Foo<"lit">; +declare let bs: Bar, bl: Bar<"lit">; +bl = bs; // Error +bs = bl; // Error +fl = fs; // Error +fs = fl; // Error diff --git a/tsc/testdata/tests/cases/compiler/varianceCycleStructuralFallback.ts b/tsc/testdata/tests/cases/compiler/varianceCycleStructuralFallback.ts new file mode 100644 index 0000000000000..e3d0f7deff7f5 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/varianceCycleStructuralFallback.ts @@ -0,0 +1,33 @@ +// @strict: true +// @noEmit: true + +// The -? mapped type makes the variance of MA unmeasurable, so comparisons +// of instantiations of MA made while measuring the variances of MA and MB +// fall back to structural comparisons. The variances should not depend on +// which type is measured first. + +// @filename: maFirst.ts +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +type MB = { f: (u: U) => void; a: MA> }; + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +al = as; +as = al; +bl = bs; +bs = bl; + +// @filename: mbFirst.ts +export {}; + +type MA = { x: { [K in keyof T]-?: T[K] }; b: MB> }; +type MB = { f: (u: U) => void; a: MA> }; + +declare let as: MA<{ p: string }>, al: MA<{ p: "lit" }>; +declare let bs: MB<{ p: string }>, bl: MB<{ p: "lit" }>; +bl = bs; +bs = bl; +al = as; +as = al; diff --git a/tsc/testdata/tests/cases/compiler/varianceMeasuredWithinCircularity.ts b/tsc/testdata/tests/cases/compiler/varianceMeasuredWithinCircularity.ts new file mode 100644 index 0000000000000..712ee43f4f782 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/varianceMeasuredWithinCircularity.ts @@ -0,0 +1,30 @@ +// @strict: true +// @noEmit: true + +// The variances of Selection and TransitionLike depend on each other. +// The callback of `data` requires Selection to be covariant in P, while +// `join` passes Selection to a callback, which then requires it to +// be contravariant in P, so Selection is invariant in P. TransitionLike +// reaches P of a Selection through `selection().children()`, so it is +// invariant in G. Both must hold whichever variance is measured first. + +export {}; + +interface Base { base: string } +interface Derived extends Base { derived: string } + +interface Selection { + data(key: (parent: P) => string): Selection; + join(enter: string | ((elem: Selection) => Selection | TransitionLike)): Selection; + children(): Selection; +} + +interface TransitionLike { + selection(): Selection; +} + +declare let s1: Selection; +let s2: Selection = s1; + +declare let t1: TransitionLike; +let t2: TransitionLike = t1;