mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 19:07:27 -06:00
Fixed crash on circular local type arguments when outer ones are present too (#59089)
Co-authored-by: Gabriela Araujo Britto <gabrielaa@microsoft.com>
This commit is contained in:
parent
652c96c123
commit
ec446b6f19
@ -16300,7 +16300,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
function getTypeArguments(type: TypeReference): readonly Type[] {
|
||||
if (!type.resolvedTypeArguments) {
|
||||
if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedTypeArguments)) {
|
||||
return type.target.localTypeParameters?.map(() => errorType) || emptyArray;
|
||||
return concatenate(type.target.outerTypeParameters, type.target.localTypeParameters?.map(() => errorType)) || emptyArray;
|
||||
}
|
||||
const node = type.node;
|
||||
const typeArguments = !node ? emptyArray :
|
||||
@ -16311,7 +16311,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
type.resolvedTypeArguments ??= type.mapper ? instantiateTypes(typeArguments, type.mapper) : typeArguments;
|
||||
}
|
||||
else {
|
||||
type.resolvedTypeArguments ??= type.target.localTypeParameters?.map(() => errorType) || emptyArray;
|
||||
type.resolvedTypeArguments ??= concatenate(type.target.outerTypeParameters, type.target.localTypeParameters?.map(() => errorType) || emptyArray);
|
||||
error(
|
||||
type.node || currentNode,
|
||||
type.target.symbol ? Diagnostics.Type_arguments_for_0_circularly_reference_themselves : Diagnostics.Tuple_type_arguments_circularly_reference_themselves,
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
circularTypeArgumentsLocalAndOuterNoCrash1.ts(5,12): error TS4109: Type arguments for 'NumArray' circularly reference themselves.
|
||||
|
||||
|
||||
==== circularTypeArgumentsLocalAndOuterNoCrash1.ts (1 errors) ====
|
||||
// https://github.com/microsoft/TypeScript/issues/59062
|
||||
|
||||
function f<_T, _S>() {
|
||||
interface NumArray<T extends number> extends Array<T> {}
|
||||
type X = NumArray<X extends {} ? number : number>;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS4109: Type arguments for 'NumArray' circularly reference themselves.
|
||||
}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts] ////
|
||||
|
||||
=== circularTypeArgumentsLocalAndOuterNoCrash1.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/59062
|
||||
|
||||
function f<_T, _S>() {
|
||||
>f : Symbol(f, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 0, 0))
|
||||
>_T : Symbol(_T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 11))
|
||||
>_S : Symbol(_S, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 14))
|
||||
|
||||
interface NumArray<T extends number> extends Array<T> {}
|
||||
>NumArray : Symbol(NumArray, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 22))
|
||||
>T : Symbol(T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 21))
|
||||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 21))
|
||||
|
||||
type X = NumArray<X extends {} ? number : number>;
|
||||
>X : Symbol(X, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 58))
|
||||
>NumArray : Symbol(NumArray, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 22))
|
||||
>X : Symbol(X, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 58))
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts] ////
|
||||
|
||||
=== circularTypeArgumentsLocalAndOuterNoCrash1.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/59062
|
||||
|
||||
function f<_T, _S>() {
|
||||
>f : <_T, _S>() => void
|
||||
> : ^ ^^ ^^^^^^^^^^^
|
||||
|
||||
interface NumArray<T extends number> extends Array<T> {}
|
||||
type X = NumArray<X extends {} ? number : number>;
|
||||
>X : NumArray<any>
|
||||
> : ^^^^^^^^^^^^^
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/59062
|
||||
|
||||
function f<_T, _S>() {
|
||||
interface NumArray<T extends number> extends Array<T> {}
|
||||
type X = NumArray<X extends {} ? number : number>;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user