Skip to content

Commit 9962011

Browse files
authored
Fix crash when circular reference in variance annotations (#48539)
* Fix crash when circular reference in variance annotations * chore: clean code
1 parent 2db17fd commit 9962011

6 files changed

+55
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20640,6 +20640,9 @@ namespace ts {
2064020640
function createMarkerType(symbol: Symbol, source: TypeParameter, target: Type) {
2064120641
const mapper = makeUnaryTypeMapper(source, target);
2064220642
const type = getDeclaredTypeOfSymbol(symbol);
20643+
if (isErrorType(type)) {
20644+
return type;
20645+
}
2064320646
const result = symbol.flags & SymbolFlags.TypeAlias ?
2064420647
getTypeAliasInstantiation(symbol, instantiateTypes(getSymbolLinks(symbol).typeParameters!, mapper)) :
2064520648
createTypeReference(type as GenericType, instantiateTypes((type as GenericType).typeParameters, mapper));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts(1,6): error TS2456: Type alias 'T1' circularly references itself.
2+
tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts(1,11): error TS2300: Duplicate identifier '(Missing)'.
3+
tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts(1,12): error TS1359: Identifier expected. 'in' is a reserved word that cannot be used here.
4+
tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts(2,6): error TS2456: Type alias 'T2' circularly references itself.
5+
6+
7+
==== tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts (4 errors) ====
8+
type T1<in in> = T1 // Error: circularly references
9+
~~
10+
!!! error TS2456: Type alias 'T1' circularly references itself.
11+
12+
!!! error TS2300: Duplicate identifier '(Missing)'.
13+
~~
14+
!!! error TS1359: Identifier expected. 'in' is a reserved word that cannot be used here.
15+
type T2<out out> = T2 // Error: circularly references
16+
~~
17+
!!! error TS2456: Type alias 'T2' circularly references itself.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [varianceAnnotationsWithCircularlyReferencesError.ts]
2+
type T1<in in> = T1 // Error: circularly references
3+
type T2<out out> = T2 // Error: circularly references
4+
5+
//// [varianceAnnotationsWithCircularlyReferencesError.js]
6+
"use strict";
7+
8+
9+
//// [varianceAnnotationsWithCircularlyReferencesError.d.ts]
10+
declare type T1<in , > = T1;
11+
declare type T2<out out> = T2;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts ===
2+
type T1<in in> = T1 // Error: circularly references
3+
>T1 : Symbol(T1, Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 0))
4+
> : Symbol((Missing), Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 8), Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 10))
5+
> : Symbol((Missing), Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 8), Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 10))
6+
>T1 : Symbol(T1, Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 0))
7+
8+
type T2<out out> = T2 // Error: circularly references
9+
>T2 : Symbol(T2, Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 19))
10+
>out : Symbol(out, Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 1, 8))
11+
>T2 : Symbol(T2, Decl(varianceAnnotationsWithCircularlyReferencesError.ts, 0, 19))
12+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotationsWithCircularlyReferencesError.ts ===
2+
type T1<in in> = T1 // Error: circularly references
3+
>T1 : any
4+
5+
type T2<out out> = T2 // Error: circularly references
6+
>T2 : any
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
type T1<in in> = T1 // Error: circularly references
5+
type T2<out out> = T2 // Error: circularly references

0 commit comments

Comments
 (0)