You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Circular reference in default type parameter crashes compiler #16221
Expected behavior:
The compiler either accepts it (so that new SelfReference() has the type SelfReference<SelfReference<string>>) or rejects it (by explicitly disallowing a circular reference in default type parameters).
Actual behavior:
The compiler goes into an infinite loop that exceeds the recursion limit:
RangeError: Maximum call stack size exceeded
at resolveNameHelper (typescript\lib\typescript.js:26480:35)
at resolveName (typescript\lib\typescript.js:26478:20)
at resolveEntityName (typescript\lib\typescript.js:27128:26)
at getTypeFromTypeReference (typescript\lib\typescript.js:31874:54)
at getTypeFromTypeNode (typescript\lib\typescript.js:32724:28)
at getDefaultFromTypeParameter (typescript\lib\typescript.js:31032:66)
⋮
Thinking about it more, I'd say the expected behavior is that
classSelfReference<T=SelfReference<string>>{}
should be accepted. Whatever is parsing SelfReference<string> should not care about resolving the default type parameter value, since the type is explicitly given as string.
On the other hand
classSelfReference<T=SelfReference>{}
should probably be rejected, since it seems to require the existence of the infinite type SelfReference<SelfReference<SelfReference<…>>>.
Activity
jcalz commentedon Jun 3, 2017
Thinking about it more, I'd say the expected behavior is that
should be accepted. Whatever is parsing
SelfReference<string>should not care about resolving the default type parameter value, since the type is explicitly given asstring.On the other hand
should probably be rejected, since it seems to require the existence of the infinite type
SelfReference<SelfReference<SelfReference<…>>>.