Skip to content

Commit 8194a58

Browse files
committed
Use outofbandVarianceHandler
1 parent b44f6a2 commit 8194a58

5 files changed

+39
-17
lines changed

src/compiler/checker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -18791,10 +18791,11 @@ namespace ts {
1879118791
// type references (which are intended by be compared structurally). Obtain the variance
1879218792
// information for the type parameters and relate the type arguments accordingly.
1879318793
const variances = getVariances((source as TypeReference).target);
18794-
// We return Ternary.Maybe for a recursive invocation of getVariances (signalled by emptyArray). This
18794+
// We return Ternary.Unknown for a recursive invocation of getVariances (signalled by emptyArray). This
1879518795
// effectively means we measure variance only from type parameter occurrences that aren't nested in
1879618796
// recursive instantiations of the generic type.
1879718797
if (variances === emptyArray) {
18798+
outofbandVarianceMarkerHandler!(/*onlyUnreliable*/ false);
1879818799
return Ternary.Unknown;
1879918800
}
1880018801
const varianceResult = relateVariances(getTypeArguments(source as TypeReference), getTypeArguments(target as TypeReference), variances, intersectionState);
@@ -19756,7 +19757,7 @@ namespace ts {
1975619757
outofbandVarianceMarkerHandler = oldHandler;
1975719758
if (unmeasurable || unreliable) {
1975819759
if (unmeasurable) {
19759-
variance |= VarianceFlags.Unmeasurable;
19760+
variance = VarianceFlags.Unmeasurable;
1976019761
}
1976119762
if (unreliable) {
1976219763
variance |= VarianceFlags.Unreliable;

tests/baselines/reference/checkOrderDependenceGenericAssignability.errors.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/compiler/checkOrderDependenceGenericAssignability.ts(24,7): error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
2-
Types of property 'child' are incompatible.
3-
Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
4-
Type 'unknown' is not assignable to type 'string'.
2+
The types of 'child.a' are incompatible between these types.
3+
Type 'unknown' is not assignable to type 'string'.
54

65

76
==== tests/cases/compiler/checkOrderDependenceGenericAssignability.ts (1 errors) ====
@@ -31,7 +30,6 @@ tests/cases/compiler/checkOrderDependenceGenericAssignability.ts(24,7): error TS
3130
const notString: Parent<string> = pu;
3231
~~~~~~~~~
3332
!!! error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
34-
!!! error TS2322: Types of property 'child' are incompatible.
35-
!!! error TS2322: Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
36-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
33+
!!! error TS2322: The types of 'child.a' are incompatible between these types.
34+
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
3735

tests/baselines/reference/objectTypeWithRecursiveWrappedProperty.errors.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedProperty.ts(13,1): error TS2322: Type 'List<string>' is not assignable to type 'List<number>'.
2-
Type 'string' is not assignable to type 'number'.
2+
Types of property 'data' are incompatible.
3+
Type 'string' is not assignable to type 'number'.
34

45

56
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedProperty.ts (1 errors) ====
@@ -18,4 +19,5 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRec
1819
list1 = list3; // error
1920
~~~~~
2021
!!! error TS2322: Type 'List<string>' is not assignable to type 'List<number>'.
21-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
22+
!!! error TS2322: Types of property 'data' are incompatible.
23+
!!! error TS2322: Type 'string' is not assignable to type 'number'.

tests/baselines/reference/objectTypeWithRecursiveWrappedProperty2.errors.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedProperty2.ts(13,1): error TS2322: Type 'List<string>' is not assignable to type 'List<number>'.
2-
Type 'string' is not assignable to type 'number'.
2+
Types of property 'data' are incompatible.
3+
Type 'string' is not assignable to type 'number'.
34

45

56
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedProperty2.ts (1 errors) ====
@@ -18,4 +19,5 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRec
1819
list1 = list3; // error
1920
~~~~~
2021
!!! error TS2322: Type 'List<string>' is not assignable to type 'List<number>'.
21-
!!! error TS2322: Type 'string' is not assignable to type 'number'.
22+
!!! error TS2322: Types of property 'data' are incompatible.
23+
!!! error TS2322: Type 'string' is not assignable to type 'number'.

tests/baselines/reference/varianceMeasurement.errors.txt

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
tests/cases/compiler/varianceMeasurement.ts(10,7): error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<"a">'.
2-
Type 'string' is not assignable to type '"a"'.
2+
Types of property 'x' are incompatible.
3+
Type 'string' is not assignable to type '"a"'.
4+
tests/cases/compiler/varianceMeasurement.ts(11,7): error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<unknown>'.
5+
The types of 'y.x' are incompatible between these types.
6+
Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
7+
Types of parameters 'arg' and 'arg' are incompatible.
8+
Type 'unknown' is not assignable to type 'string'.
39
tests/cases/compiler/varianceMeasurement.ts(21,7): error TS2322: Type 'Foo2<string>' is not assignable to type 'Foo2<"a">'.
410
Types of property 'x' are incompatible.
511
Type 'string' is not assignable to type '"a"'.
@@ -19,14 +25,17 @@ tests/cases/compiler/varianceMeasurement.ts(45,7): error TS2322: Type 'Foo4<stri
1925
Types of parameters 'arg' and 'arg' are incompatible.
2026
Type 'unknown' is not assignable to type 'string'.
2127
tests/cases/compiler/varianceMeasurement.ts(57,7): error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<unknown, number>'.
22-
Type 'unknown' is not assignable to type 'string'.
28+
The types returned by 'then(...)' are incompatible between these types.
29+
Type 'Fn<string, any>' is not assignable to type 'Fn<unknown, any>'.
30+
Types of parameters 'a' and 'a' are incompatible.
31+
Type 'unknown' is not assignable to type 'string'.
2332
tests/cases/compiler/varianceMeasurement.ts(62,7): error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<string, 0>'.
2433
Type 'number' is not assignable to type '0'.
2534
tests/cases/compiler/varianceMeasurement.ts(75,7): error TS2322: Type 'C<unknown, number>' is not assignable to type 'C<unknown, string>'.
2635
Type 'number' is not assignable to type 'string'.
2736

2837

29-
==== tests/cases/compiler/varianceMeasurement.ts (9 errors) ====
38+
==== tests/cases/compiler/varianceMeasurement.ts (10 errors) ====
3039
// The type below should be invariant in T but is measured as covariant because
3140
// we don't analyze recursive references.
3241

@@ -39,8 +48,15 @@ tests/cases/compiler/varianceMeasurement.ts(75,7): error TS2322: Type 'C<unknown
3948
const f11: Foo1<'a'> = f10;
4049
~~~
4150
!!! error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<"a">'.
42-
!!! error TS2322: Type 'string' is not assignable to type '"a"'.
51+
!!! error TS2322: Types of property 'x' are incompatible.
52+
!!! error TS2322: Type 'string' is not assignable to type '"a"'.
4353
const f12: Foo1<unknown> = f10;
54+
~~~
55+
!!! error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<unknown>'.
56+
!!! error TS2322: The types of 'y.x' are incompatible between these types.
57+
!!! error TS2322: Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
58+
!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible.
59+
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
4460

4561
// The type below is invariant in T and is measured as such.
4662

@@ -112,7 +128,10 @@ tests/cases/compiler/varianceMeasurement.ts(75,7): error TS2322: Type 'C<unknown
112128
const fn1: Fn<unknown, number> = fn; // Error
113129
~~~
114130
!!! error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<unknown, number>'.
115-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
131+
!!! error TS2322: The types returned by 'then(...)' are incompatible between these types.
132+
!!! error TS2322: Type 'Fn<string, any>' is not assignable to type 'Fn<unknown, any>'.
133+
!!! error TS2322: Types of parameters 'a' and 'a' are incompatible.
134+
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
116135
const fn2: Fn<'a', number> = fn;
117136

118137
// Covariant in B

0 commit comments

Comments
 (0)