-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Compiler error - "Maximum call stack size exceeded" #2997
Comments
I've identified the cause. The problem is that in a union type, we do a reduction step where we remove constituents that are subtypes of other constituents. To do that, we have to use the subtype relation, which calls checkTypeRelatedTo. But in the process of comparing union types, we have to perform subtype reduction again. checkTypeRelatedTo has way of dealing with infinite recursion if all the infinite recursion happens inside a particular call to it. But in this case, the recursion is spread over multiple calls, and no single call is deep enough for us to catch the recursion. The options are:
I am leaning towards option 3. |
I confirmed that the original code also compiles with @JsonFreeman's fix. Thanks! |
I'm experiencing this error with a source file importing a d.ts file with module aliases (via "/// <reference"). Unfortunately it's hard for me to extract what exactly causes the compiler to crash. With TS 1.4.1 my code is being compiled just fine. |
@evil-shrike can you give the latest from branch release-1.5 a try. all you need is tsc.js and lib.d.ts from https://github.com/Microsoft/TypeScript/tree/release-1.5/bin |
@mhegazy I've tried the release-1.5 branch and got the error on it. |
can you share the code sample that causes the issue? |
@evil-shrike, looks like this was never ported to branch release-1.5, my appologies. can you try the latest from master instead? |
reopening to port to release-1.5 |
#3071 was indeed ported to release-1.5, and that should be sufficient to fix the issue. |
@evil-shrike Can you try it on master and see if it works? |
I've tried master and still have "RangeError: Maximum call stack size exceeded":
Unfortunately I can't share the reproducible code sample currently (it fails on whole project but stop failing as I start removing files). I'll try to create a reproducible sample... |
Thanks. Also, do you have a longer stack trace? |
This is all I have. Is there a way to tell compiler to output more details? |
I have a guess as to what's going on. I will create a branch for you to try. |
I've pushed a branch https://github.com/Microsoft/TypeScript/tree/deeplyNestedTypeArgumentInference. It is based on master, but I would do the same fix on release-1.5. Can you give it a try? In the meantime, I will try to come up with a sample for the problem I think you're having. |
Oh also, you need to build using "jake local", and grab the output from the folder |
I've built the branch and run but unfortunately it fails with the same error (I hope I didn't miss anything):
|
In the typescript repo, you have to run |
Also, I think I have a sample, which is inspired by #3309: function foo<T>() {
var z = foo<typeof y>();
var y: {
y2: typeof z
};
return y;
}
function bar<T>() {
var z = bar<typeof y>();
var y: {
y2: typeof z;
}
return y;
}
var a = foo<number>();
var b = bar<number>();
function test<T>(x: typeof a): void { }
test(b); |
I've opened #3451 for this. |
I have a pull request #3452 that addresses what I think your issue is. At least it fixes the same stack overflow you are getting, even if you are not getting it in the same way. |
closing this in favor of new issue #3452. |
(1.5 beta)
This is the most I can reduce it while still having it crash:
tsc foo.ts -t es5
Alternative call stack for the crash (same code):
The original code from which this test case is derived is here.
Edit: Reduced the case some more - removed the
fullName
getters and simplified the types ofmember
.The text was updated successfully, but these errors were encountered: