From dbb17b8bc05b6efb9d1a4292f84bef80d4ca4eba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Oct 2025 22:06:42 +0000 Subject: [PATCH 1/3] Initial plan From da27ef1b88df6b43cbd3a298e8c42b2b47dce0dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Oct 2025 22:20:44 +0000 Subject: [PATCH 2/3] Port PR 62604: Propagate variance reliability flags Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- internal/checker/relater.go | 44 +++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/internal/checker/relater.go b/internal/checker/relater.go index 4f101352ff..a4abe4cc93 100644 --- a/internal/checker/relater.go +++ b/internal/checker/relater.go @@ -3878,26 +3878,32 @@ func (r *Relater) typeArgumentsRelatedTo(sources []*Type, targets []*Type, varia } else { related = r.c.compareTypesIdentical(s, t) } - } else if variance == VarianceFlagsCovariant { - related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) - } else if variance == VarianceFlagsContravariant { - related = r.isRelatedToEx(t, s, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) - } else if variance == VarianceFlagsBivariant { - // In the bivariant case we first compare contravariantly without reporting - // errors. Then, if that doesn't succeed, we compare covariantly with error - // reporting. Thus, error elaboration will be based on the covariant check, - // which is generally easier to reason about. - related = r.isRelatedTo(t, s, RecursionFlagsBoth, false /*reportErrors*/) - if related == TernaryFalse { - related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) - } } else { - // In the invariant case we first compare covariantly, and only when that - // succeeds do we proceed to compare contravariantly. Thus, error elaboration - // will typically be based on the covariant check. - related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) - if related != TernaryFalse { - related &= r.isRelatedToEx(t, s, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + // Propagate unreliable variance flag + if r.c.inVarianceComputation && varianceFlags&VarianceFlagsUnreliable != 0 { + r.c.instantiateType(s, r.c.reportUnreliableMapper) + } + if variance == VarianceFlagsCovariant { + related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + } else if variance == VarianceFlagsContravariant { + related = r.isRelatedToEx(t, s, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + } else if variance == VarianceFlagsBivariant { + // In the bivariant case we first compare contravariantly without reporting + // errors. Then, if that doesn't succeed, we compare covariantly with error + // reporting. Thus, error elaboration will be based on the covariant check, + // which is generally easier to reason about. + related = r.isRelatedTo(t, s, RecursionFlagsBoth, false /*reportErrors*/) + if related == TernaryFalse { + related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + } + } else { + // In the invariant case we first compare covariantly, and only when that + // succeeds do we proceed to compare contravariantly. Thus, error elaboration + // will typically be based on the covariant check. + related = r.isRelatedToEx(s, t, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + if related != TernaryFalse { + related &= r.isRelatedToEx(t, s, RecursionFlagsBoth, reportErrors, nil /*headMessage*/, intersectionState) + } } } if related == TernaryFalse { From 3eded0b8d399079a1fb85b1aa428b2fa81d6b1e1 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:21:03 -0700 Subject: [PATCH 3/3] Update baselines --- .../compiler/variancePropagation.errors.txt | 29 ---------------- .../variancePropagation.errors.txt.diff | 33 ------------------- 2 files changed, 62 deletions(-) delete mode 100644 testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt delete mode 100644 testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt.diff diff --git a/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt b/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt deleted file mode 100644 index 90d0a6c86d..0000000000 --- a/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -variancePropagation.ts(13,7): error TS2322: Type 'DerivedTable<{ base: Base; new: New; }>' is not assignable to type 'DerivedTable<{ base: Base; new: New & Base; }>'. - Type '{ base: Base; new: New; }' is not assignable to type '{ base: Base; new: New & Base; }'. - Types of property 'new' are incompatible. - Type 'New' is not assignable to type 'New & Base'. - Property 'baseProp' is missing in type 'New' but required in type 'Base'. - - -==== variancePropagation.ts (1 errors) ==== - // https://github.com/microsoft/TypeScript/issues/62606 - - interface DerivedTable { - // Error disappears when these property declarations are reversed - schema: S["base"] & S["new"] - readonlySchema: Readonly - } - - interface Base { baseProp: number; } - interface New { newProp: boolean; } - - declare const source: DerivedTable<{ base: Base, new: New }> - const destination: DerivedTable<{ base: Base; new: New & Base }> = source; // Error - ~~~~~~~~~~~ -!!! error TS2322: Type 'DerivedTable<{ base: Base; new: New; }>' is not assignable to type 'DerivedTable<{ base: Base; new: New & Base; }>'. -!!! error TS2322: Type '{ base: Base; new: New; }' is not assignable to type '{ base: Base; new: New & Base; }'. -!!! error TS2322: Types of property 'new' are incompatible. -!!! error TS2322: Type 'New' is not assignable to type 'New & Base'. -!!! error TS2322: Property 'baseProp' is missing in type 'New' but required in type 'Base'. -!!! related TS2728 variancePropagation.ts:9:18: 'baseProp' is declared here. - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt.diff deleted file mode 100644 index a6579d94a7..0000000000 --- a/testdata/baselines/reference/submodule/compiler/variancePropagation.errors.txt.diff +++ /dev/null @@ -1,33 +0,0 @@ ---- old.variancePropagation.errors.txt -+++ new.variancePropagation.errors.txt -@@= skipped -0, +0 lines =@@ -- -+variancePropagation.ts(13,7): error TS2322: Type 'DerivedTable<{ base: Base; new: New; }>' is not assignable to type 'DerivedTable<{ base: Base; new: New & Base; }>'. -+ Type '{ base: Base; new: New; }' is not assignable to type '{ base: Base; new: New & Base; }'. -+ Types of property 'new' are incompatible. -+ Type 'New' is not assignable to type 'New & Base'. -+ Property 'baseProp' is missing in type 'New' but required in type 'Base'. -+ -+ -+==== variancePropagation.ts (1 errors) ==== -+ // https://github.com/microsoft/TypeScript/issues/62606 -+ -+ interface DerivedTable { -+ // Error disappears when these property declarations are reversed -+ schema: S["base"] & S["new"] -+ readonlySchema: Readonly -+ } -+ -+ interface Base { baseProp: number; } -+ interface New { newProp: boolean; } -+ -+ declare const source: DerivedTable<{ base: Base, new: New }> -+ const destination: DerivedTable<{ base: Base; new: New & Base }> = source; // Error -+ ~~~~~~~~~~~ -+!!! error TS2322: Type 'DerivedTable<{ base: Base; new: New; }>' is not assignable to type 'DerivedTable<{ base: Base; new: New & Base; }>'. -+!!! error TS2322: Type '{ base: Base; new: New; }' is not assignable to type '{ base: Base; new: New & Base; }'. -+!!! error TS2322: Types of property 'new' are incompatible. -+!!! error TS2322: Type 'New' is not assignable to type 'New & Base'. -+!!! error TS2322: Property 'baseProp' is missing in type 'New' but required in type 'Base'. -+!!! related TS2728 variancePropagation.ts:9:18: 'baseProp' is declared here. -+ \ No newline at end of file