Skip to content

Guard against recursion in inferTypeForHomomorphicMappedType #38224

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

Merged
merged 2 commits into from
Apr 28, 2020

Conversation

ahejlsberg
Copy link
Member

Fixes #38198.

@ahejlsberg
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 27, 2020

Heya @ahejlsberg, I've started to run the extended test suite on this PR at 8648986. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 27, 2020

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 8648986. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 27, 2020

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 8648986. You can monitor the build here.

@ahejlsberg
Copy link
Member Author

Test runs all appear to be clean (issues are preexisting conditions).

@@ -18267,12 +18268,16 @@ namespace ts {
* variable T[P] (i.e. we treat the type T[P] as the type variable we're inferring for).
*/
function inferTypeForHomomorphicMappedType(source: Type, target: MappedType, constraint: IndexType): Type | undefined {
if (inInferTypeForHomomorphicMappedType) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to cache this inference failure, as in invokeOnce, so if it's attempted again on the same types outside the same recursive context (but during the same traversal) we still refuse to perform the secondary inference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. In the general case this function is never recursive. The only code paths that could recur are special cases for array and tuple types, so we're talking something that happens very rarely. I think this simple solution is fine.

@ahejlsberg ahejlsberg merged commit a0ebd2c into master Apr 28, 2020
@ahejlsberg ahejlsberg deleted the fix38198 branch April 28, 2020 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

recursive type crashes tsc with RangeError: Maximum call stack size exceeded
3 participants