Skip to content

Maximum call stack size exceeded #20330

Description

TypeScript Version: 2.7.0-dev.20171129

Code

export class Type<A> {
  // prettier-ignore
  readonly '_A': A
}
export type Any = Type<any>

export class ArrayType<RT extends Any> extends Type<Array<RT['_A']>> {}
export interface TTypeArrayType extends ArrayType<TType> {}

export type TType = TTypeArrayType

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)

Activity

  1. sledorze commented on Nov 29, 2017

    @sledorze
    Author

    Maybe related to #20064

  2. sandersn commented on Nov 30, 2017

    @sandersn
    Member

    Could be related, but #20370 does not fix it, and it doesn't have any mapped types, so I think it's a different issue.

  3. sandersn commented on Nov 30, 2017

    @sandersn
    Member

    Here's a simpler repro:

    type Type<A> = { a: A }
    interface ArrayType<RT> extends Type<RT['a']> {}
    interface TTypeArrayType extends ArrayType<TTypeArrayType> {}
  4. weswigham commented on Nov 30, 2017

    @weswigham
    Member

    Maybe related to #16861? Repro is similar, anyway (recursively defined type with indexed access).

  5. sandersn commented on Dec 1, 2017

    @sandersn
    Member

    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> { }
    1. Resolve the members of X.
    2. Examine base types for members: get properties of L<X>
    3. Resolve members of L<X> by resolving L<RT>, then instantiating L<RT> with RT=X.
    4. Instantiate base types of L<RT> with RT=X: T<RT['a']>.
    5. Instantiate T<RT['a']> with RT=X.
    6. Instantiate RT['a'] with RT=X.
    7. The resulting type, X['a'], doesn't have any type parameters. Just use the type of X.a.
    8. So get the property a of X.
    9. 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.

  6. sandersn commented on Dec 1, 2017

    @sandersn
    Member

    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.

  7. sandersn commented on Dec 1, 2017

    @sandersn
    Member

    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.

  8. sledorze commented on Dec 23, 2017

    @sledorze
    Author

    Nathan Shively-Sanders (@sandersn) can you explain what would be the behaviour for that use case? (generates an error or compile successfully? - thanks)

  9. sandersn commented on Jan 2, 2018

    @sandersn
    Member

    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 because X will have a property a because it eventually extends T<A>.

  10. sledorze commented on Jan 2, 2018

    @sledorze
    Author
  11. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions