Closed falsandtru closed 6 years ago
Some 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"
]
}
@sandersn Can you see the repro?
Thanks for the additional detail. Can you repro this outside Travis?
I can repro on my local machine.
What does your file structure look like? What version of tsc.js are you using?
Same as https://travis-ci.org/falsandtru/TypeScript/builds/301501435. Can't you repro using that my commit???
You 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.
~/TypeScript/built/local/tsc.js index.ts
This crash must be from interaction with the contents of node_modules
because if you drop index.ts
into a new directory, the crash doesn't happen. If you copy Typescript's node_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.
Here is a repro for local machines:
jake local
.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 exceeded
the crash is very likely an infinite loop caused by the interaction between contextual typing and type inference.
I think so.
~/TypeScript/temp/index.ts
or ~/temp/index.ts
? Anywhere that node resolution will find TypeScript's node_modules
should cause the crash.
Ah, so can you repro and confirm this bug?
Another 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.
Fix is up at #20370.
From https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lodash
cc @sandersn @ahejlsberg
TypeScript Version: master
Code
Expected behavior:
pass
Actual behavior: