Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interchanging identical classes with generics causes Maximum call stack size exceeded #17148

Closed
MarcusLongmuir opened this issue Jul 12, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority

Comments

@MarcusLongmuir
Copy link

TypeScript Version: 2.4.1 and latest (2.5.0-dev.20170712) nightly. Not present in 2.4.0 (is a regression)

Code

class Foo {
  myFunc<T extends Foo>(arg: T) {}
}

class Bar {
  myFunc<T extends Bar>(arg: T) {}
}

const myVar: Foo = new Bar();

Expected behavior:
Should compile without error as it does on 2.4.0.

Actual behavior:

.../node_modules/typescript/lib/typescript.js:1553
                if (!callback(array[i], i)) {
                     ^
RangeError: Maximum call stack size exceeded
    at Object.every (.../node_modules/typescript/lib/typescript.js:1553:22)
    at isWeakType (.../node_modules/typescript/lib/typescript.js:35348:28)
    at isRelatedTo (.../node_modules/typescript/lib/typescript.js:34803:21)
    at checkTypeRelatedTo (.../node_modules/typescript/lib/typescript.js:34697:26)
    at isTypeRelatedTo (.../node_modules/typescript/lib/typescript.js:34673:24)
    at isTypeAssignableTo (.../node_modules/typescript/lib/typescript.js:34373:20)
    at getInferredType (.../node_modules/typescript/lib/typescript.js:36490:26)
    at getInferredTypes (.../node_modules/typescript/lib/typescript.js:36500:29)
    at instantiateSignatureInContextOf (.../node_modules/typescript/lib/typescript.js:40435:57)
    at compareSignaturesRelated (.../node_modules/typescript/lib/typescript.js:34423:26)

The example is rather contrived, but I arrived at this reproduction case by stripping away an entire library in which package A has a dependency installed that package B also has installed; in that case the class from the dependency is identical and package A expects to be able to call into package B, but to simplify the reproduction I've made two classes that are identical in all but name and it seems to result in the same error.

This seems related to #16533, #16221, and #15926, however those issues are present in 2.4.0 whereas this is not.

@0815fox
Copy link

0815fox commented Jul 18, 2017

I also get a Maximum call stack size exceeded in compareSignaturesRelated which suddenly appeared in 2.4.1. However, in my case it exceeds in a more friendly way, where the recursion is more obvious from the stack trace:

/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:55776
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at getNumParametersToCheckForSignatureRelatability (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28702:65)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28614:30)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)
    at compareSignaturesRelated (/builds/cloud/refreshable/node_modules/typescript/lib/tsc.js:28625:21)

Unfortunately I cannot say, what causes it in my case.
I can confirm, that @MarcusLongmuir s sample code leads to a max call stack size exceeded exception. It still leads to an exception, when Bar extends Foo, but to another trace:

/usr/lib/node_modules/typescript/lib/tsc.js:55776
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at /usr/lib/node_modules/typescript/lib/tsc.js:28228:29
    at mapper (/usr/lib/node_modules/typescript/lib/tsc.js:28270:64)
    at instantiateTypeNoAlias (/usr/lib/node_modules/typescript/lib/tsc.js:28455:24)
    at instantiateType (/usr/lib/node_modules/typescript/lib/tsc.js:28449:24)
    at getTypeOfInstantiatedSymbol (/usr/lib/node_modules/typescript/lib/tsc.js:25470:32)
    at getTypeOfSymbol (/usr/lib/node_modules/typescript/lib/tsc.js:25492:24)
    at getTypeOfParameter (/usr/lib/node_modules/typescript/lib/tsc.js:34415:24)
    at getTypeAtPosition (/usr/lib/node_modules/typescript/lib/tsc.js:34427:53)
    at forEachMatchingParameterType (/usr/lib/node_modules/typescript/lib/tsc.js:30030:26)
    at instantiateSignatureInContextOf (/usr/lib/node_modules/typescript/lib/tsc.js:33592:13)

I will now try to run my program with 2.4.0 and report, if my case also only appears with 2.4.1.

@0815fox
Copy link

0815fox commented Jul 18, 2017

I can verify, that @MarcusLongmuir s case does not fail with 2.4.0.
In our case it also fails for typescript version 2.4.0 but does not fail with 2.3.4.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 18, 2017
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.5 milestone Jul 18, 2017
@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned sandersn Aug 5, 2017
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Aug 5, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue High Priority
Projects
None yet
Development

No branches or pull requests

6 participants