Skip to content

Evolving array element type ignores contextual type#15075

Merged
sandersn merged 2 commits into
masterfrom
fix-exponential-expanding-array-assignment
Apr 17, 2017
Merged

Evolving array element type ignores contextual type#15075
sandersn merged 2 commits into
masterfrom
fix-exponential-expanding-array-assignment

Conversation

@sandersn
Copy link
Copy Markdown
Member

@sandersn sandersn commented Apr 7, 2017

Control flow analysis can easily hit circularities or exponential behaviour when requesting the contextual type of an expression. When adding an element type to an evolving array type, there is no point in checking the contextual type of the new element type because it is unknown -- it is exactly the type of the evolving array, which is in the middle of being found.

Fixes #14628

This is code of the form:

let x = []
x[0] = { contextual: 'no' }
x[1] = { contextual: 'should not check' }
x[2] = { contextual: 'contextual type' }
// :
// :

I considered adding a third parameter to getTypeOfExpression and calling checkExpressionWithContextualType, but I decided having a new function that delegates to getTypeOfExpression is less confusing.

sandersn added 2 commits April 7, 2017 11:10
Control flow analysis can easily hit circularities or exponential
behaviour when requesting the contextual type of an expression. When
adding an element type to an evolving array type, there is no point in
checking the contextual type of the new element type because it is
unknown -- it is exactly the type of the evolving array, which is
in the middle of being found.

Fixes #14628

This is code of the form:

```ts
let x = []
x[0] = { contextual: 'no' }
x[1] = { contextual: 'should not check' }
x[2] = { contextual: 'contextual type' }
// :
// :
```
Previously, the compiler would run out of memory for more than 13 or 14
of these assignments.
@lbguilherme
Copy link
Copy Markdown

Please release this fix for 2.3.x, this is breaking most of my projects. It was not released with 2.3.1, I'm forced to use @next in production.

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Apr 28, 2017

this fix specifically made it to release 2.3.1 and 2.3.2. if that is not working for you then there is a different issue here that we need to investigate.

@eteeselink
Copy link
Copy Markdown

I'm running into exactly this problem on 2.3.2. The VS Code language service works fine, webpack (with awesome-typescript-loader) crashes.

Our code is proprietaty but I'll happily share it privately with a TypeScript team member if that helps. Email me at egbert@talkjs.com if this is an option.

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented May 9, 2017

I'm running into exactly this problem on 2.3.2. The VS Code language service works fine, webpack (with awesome-typescript-loader) crashes.

does it fail with tsc --p <tscofig.json> ? if so please file a new issue and share some context. we are open to getting the repro over email if this works better for you.

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants