Repository navigation
Maximum call stack size exceeded #20330
Description
Activity
Maybe related to #20064
sandersn commented
on Nov 30, 2017 MemberMore actionsCould be related, but #20370 does not fix it, and it doesn't have any mapped types, so I think it's a different issue.
sandersn commented
on Nov 30, 2017 MemberMore actionsHere's a simpler repro:
type Type<A> = { a: A } interface ArrayType<RT> extends Type<RT['a']> {} interface TTypeArrayType extends ArrayType<TTypeArrayType> {}
Maybe related to #16861? Repro is similar, anyway (recursively defined type with indexed access).
Here's an analysis of the recursive loop. I haven't got a fix yet.
I'll use this renamed example to make things easier to type:
interface T<A> { a: A } interface L<RT> extends T<RT["a"]> { } interface X extends L<X> { }
- Resolve the members of
X. - Examine base types for members: get properties of
L<X> - Resolve members of
L<X>by resolvingL<RT>, then instantiatingL<RT>withRT=X. - Instantiate base types of
L<RT>withRT=X:T<RT['a']>. - Instantiate
T<RT['a']>withRT=X. - Instantiate
RT['a']withRT=X. - The resulting type,
X['a'], doesn't have any type parameters. Just use the type ofX.a. - So get the property
aofX. - First, resolve the members of
X.... (goto 1)
I don't think there's any provision for catching loops like this in instantiation or member resolution. It would probably be enough to put a check in resolveStructuredTypeMembers.
- Resolve the members of
I have a very simple fix, but one of our tests shows that dynamic name resolution incorrectly relies on being able to recursively resolve a type's properties. I'll put up an initial PR and look into fixing dynamic name resolution.
Wesley Wigham (@weswigham) I tested the #16861 repro and #20370 doesn't fix it. There, the problem is that structured type resolution fails to resolve a property. In this bug, it keeps trying forever to resolve the property.
Nathan Shively-Sanders (@sandersn) can you explain what would be the behaviour for that use case? (generates an error or compile successfully? - thanks)
As long as the example above is modified to have
L<RT extends T<any>>then it should compile with no errors. I think that's becauseXwill have a propertyabecause it eventually extendsT<A>.- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jan 11, 2018 - locked and limited conversation to collaborators
on Jul 3, 2018
TypeScript Version: 2.7.0-dev.20171129
Code
Expected behavior:
Compiles fine or generate a meaningful error.
Actual behavior:
RangeError: Maximum call stack size exceeded
at getObjectFlags (..../node_modules/typescript/lib/tsc.js:19874:32)
at isGenericObjectType (..../node_modules/typescript/lib/tsc.js:25677:17)
at getIndexedAccessType (..../node_modules/typescript/lib/tsc.js:25723:94)
at instantiateType (..../node_modules/typescript/lib/tsc.js:26261:28)
at instantiateList (..../node_modules/typescript/lib/tsc.js:26037:33)
at instantiateTypes (..../node_modules/typescript/lib/tsc.js:26044:20)
at instantiateType (..../node_modules/typescript/lib/tsc.js:26248:65)
at instantiateList (..../node_modules/typescript/lib/tsc.js:26037:33)
at instantiateTypes (..../node_modules/typescript/lib/tsc.js:26044:20)
at instantiateType (..../node_modules/typescript/lib/tsc.js:26248:65)