Repository navigation
Stack overflow with recursive mapped types #19951
Description
Activity
sandersn commented
on Nov 13, 2017 MemberMore actionsSome notes on this:
Two weeks ago when I was testing DefinitelyTyped frequently, lodash crashed the compiler. Last week it stopped doing so.
I just compiled lodash just now and couldn't repro the problem. I copied the repro above into a buffer and couldn't repro the problem in the compiler or the language service (although my language service is from last week). Here is my test tsconfig.
{ "compilerOptions": { "strict": true, "target": "es6", "lib": ["es5", "dom"], "allowJs": true, "checkJs": true, "outDir": "out", "jsx": "preserve", "module": "commonjs" }, "include": [ "welove.ts", "first.ts", "test.js" ] }- addedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Nov 13, 2017 falsandtru commented
on Nov 13, 2017 ContributorAuthorMore actionsfalsandtru commented
on Nov 14, 2017 ContributorAuthorMore actionsNathan Shively-Sanders (@sandersn) Can you see the repro?
sandersn commented
on Nov 14, 2017 MemberMore actionsThanks for the additional detail. Can you repro this outside Travis?
falsandtru commented
on Nov 14, 2017 ContributorAuthorMore actionsI can repro on my local machine.
sandersn commented
on Nov 14, 2017 MemberMore actionsWhat does your file structure look like? What version of tsc.js are you using?
falsandtru commented
on Nov 14, 2017 ContributorAuthorMore actionsSame as https://travis-ci.org/falsandtru/TypeScript/builds/301501435. Can't you repro using that my commit???
sandersn commented
on Nov 14, 2017 MemberMore actionsYou edited travis.yml, and I have no idea how to use that to repro on a local machine. Here is the information I expected:
I ended up getting the crash from the typescript repo.
- Put the original text in ~/TypeScript/index.ts.
- Run
~/TypeScript/built/local/tsc.js index.ts
This crash must be from interaction with the contents of
node_modulesbecause if you dropindex.tsinto a new directory, the crash doesn't happen. If you copy Typescript'snode_modules, the crash does happen.The similar code
var result: Partial<Struct> var result = f()does not crash, so the crash is very likely an infinite loop caused by the interaction between contextual typing and type inference.
falsandtru commented
on Nov 14, 2017 ContributorAuthorMore actionsHere is a repro for local machines:
- Put the original text in ~/TypeScript/index.ts.
- Run
jake local. - Run
node built/local/tsc.js index.ts.
if you drop index.ts into a new directory, the crash doesn't happen.
It seems not true.
$ node built/local/tsc.js temp/index.ts ...\TypeScript\built\local\tsc.js:73313 throw e; ^ RangeError: Maximum call stack size exceededthe crash is very likely an infinite loop caused by the interaction between contextual typing and type inference.
I think so.
sandersn commented
on Nov 14, 2017 MemberMore actions~/TypeScript/temp/index.tsor~/temp/index.ts? Anywhere that node resolution will find TypeScript'snode_modulesshould cause the crash.- removedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Nov 15, 2017 falsandtru commented
on Nov 15, 2017 ContributorAuthorMore actionsAh, so can you repro and confirm this bug?
sandersn commented
on Nov 30, 2017 MemberMore actionsAnother Microsoft team encountered a very similar crash resulting from lodash. Here's the simplified repro:
interface A { a: A } declare let a: A type Deep<T> = { [K in keyof T]: Deep<T[K]> } declare function f<T>(deep: Deep<T>): void f(a)
This works with HTMLElement too, so I think you could easily produce a crash like this:
import _ = require('lodash') class C { elements: HTMLElement[] doWork(e: HTMLElement) { this.elements = _.remove(this.elements, e) } }
Which is similar to code that people write every day.
sandersn commented
on Nov 30, 2017 MemberMore actionsFix is up at #20370.
Reacted by falsandtru- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Dec 2, 2017 - locked and limited conversation to collaborators
on Jun 14, 2018
From https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash
cc Nathan Shively-Sanders (@sandersn) Anders Hejlsberg (@ahejlsberg)
TypeScript Version: master
Code
Expected behavior:
pass
Actual behavior: