microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.16k stars 12.38k forks source link

Debug Failure. False expression. #18254

Closed cevek closed 6 years ago

cevek commented 7 years ago

TypeScript Version: 2.6.0-dev.20170904

Trace:

/usr/local/lib/node_modules/typescript/lib/tsc.js:56399
                throw e;
                ^

Error: Debug Failure. False expression.
    at createTypeMapper (/usr/local/lib/node_modules/typescript/lib/tsc.js:24927:22)
    at checkTypeArguments (/usr/local/lib/node_modules/typescript/lib/tsc.js:30509:38)
    at resolveCall (/usr/local/lib/node_modules/typescript/lib/tsc.js:30794:17)
    at resolveCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:30962:20)
    at resolveSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:31138:28)
    at getResolvedSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:31158:26)
    at checkCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:31201:29)
    at checkExpressionWorker (/usr/local/lib/node_modules/typescript/lib/tsc.js:32490:28)
    at checkExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:32430:42)
    at checkExpressionCached (/usr/local/lib/node_modules/typescript/lib/tsc.js:32346:38)
    at getTypeOfExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:32415:28)
    at checkDeclarationInitializer (/usr/local/lib/node_modules/typescript/lib/tsc.js:32356:24)
    at getTypeForVariableLikeDeclaration (/usr/local/lib/node_modules/typescript/lib/tsc.js:21839:28)
    at getWidenedTypeForVariableLikeDeclaration (/usr/local/lib/node_modules/typescript/lib/tsc.js:21954:24)
    at getTypeOfVariableOrParameterOrProperty (/usr/local/lib/node_modules/typescript/lib/tsc.js:22002:28)
    at checkVariableLikeDeclaration (/usr/local/lib/node_modules/typescript/lib/tsc.js:34111:41)
    at checkVariableDeclaration (/usr/local/lib/node_modules/typescript/lib/tsc.js:34161:20)
    at checkSourceElement (/usr/local/lib/node_modules/typescript/lib/tsc.js:35739:28)
    at Object.forEach (/usr/local/lib/node_modules/typescript/lib/tsc.js:275:30)
    at checkVariableStatement (/usr/local/lib/node_modules/typescript/lib/tsc.js:34169:16)
    at checkSourceElement (/usr/local/lib/node_modules/typescript/lib/tsc.js:35708:28)
    at Object.forEach (/usr/local/lib/node_modules/typescript/lib/tsc.js:275:30)
    at checkSourceFileWorker (/usr/local/lib/node_modules/typescript/lib/tsc.js:35812:20)
    at checkSourceFile (/usr/local/lib/node_modules/typescript/lib/tsc.js:35797:13)
    at getDiagnosticsWorker (/usr/local/lib/node_modules/typescript/lib/tsc.js:35850:17)
    at Object.getDiagnostics (/usr/local/lib/node_modules/typescript/lib/tsc.js:35839:24)
    at /usr/local/lib/node_modules/typescript/lib/tsc.js:56414:85
    at runWithCancellationToken (/usr/local/lib/node_modules/typescript/lib/tsc.js:56392:24)
    at getSemanticDiagnosticsForFileNoCache (/usr/local/lib/node_modules/typescript/lib/tsc.js:56406:20)
    at getAndCacheDiagnostics (/usr/local/lib/node_modules/typescript/lib/tsc.js:56614:26)
    at getSemanticDiagnosticsForFile (/usr/local/lib/node_modules/typescript/lib/tsc.js:56403:20)
    at /usr/local/lib/node_modules/typescript/lib/tsc.js:56360:24
    at Object.flatMap (/usr/local/lib/node_modules/typescript/lib/tsc.js:507:25)
    at getDiagnosticsHelper (/usr/local/lib/node_modules/typescript/lib/tsc.js:56356:56)
    at Object.getSemanticDiagnostics (/usr/local/lib/node_modules/typescript/lib/tsc.js:56367:20)
    at compileProgram (/usr/local/lib/node_modules/typescript/lib/tsc.js:59366:43)
    at compile (/usr/local/lib/node_modules/typescript/lib/tsc.js:59323:26)
    at performCompilation (/usr/local/lib/node_modules/typescript/lib/tsc.js:59212:33)
    at Object.executeCommandLine (/usr/local/lib/node_modules/typescript/lib/tsc.js:59155:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/typescript/lib/tsc.js:59513:4)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
cevek commented 7 years ago

it throws at something like that

export const rProfile = r.addChild<ProfileP>('/profile/:type', Profile);
export const rRating = r.addChild<RatingP>('/rating/:type', Rating);
export const rMatch = r.addChild<MatchP>('/match/:slug', Match);
...
addChild<ChildUrlParams extends UrlParams = UrlParams, ChildSearchParams extends SearchParams = SearchParams>(pathString: string, component: ComponentClass<ChildUrlParams, ChildSearchParams, {}>, options?: RouteOptions<ChildSearchParams>): Route<ChildUrlParams, ChildSearchParams, {}>;
mhegazy commented 7 years ago

Can you share a sample project?

cevek commented 7 years ago

Minimum reproducible project test.zip

adz5a commented 7 years ago

Hello, I am not sure this is the same problem but I experience a similar issue : I try to make an Interface with a call signature, then declare a function of this type. When the implementation is not correct but the function is not called, I get the error ( TS 2322 ), but when the function is called, I get the Debug failure error which crashes the compiler.

Here is a gist which reproduces the error.

After a little bit of investigation, it seems that the behaviour changed upon 2.5.0 release. From my gist if you change the version to typescript@2.4.2 you get the expected behaviour :

Edit : My mistake, see below, my issue is related to the pretty compiler option.

cevek commented 7 years ago

@adz5a I think it is other issue, you need create new issue

srghma commented 7 years ago

I have same error when compilerOptions.pretty = true

 ✘  ~/projects/my-nextjs-typescript-boilerplate   master ●  yr dev:ts
yarn run v0.28.4
$ tsc --watch
/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:2062
            throw e;
            ^

Error: Debug Failure. False expression.
    at computePositionOfLineAndCharacter (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:3752:22)
    at Object.getPositionOfLineAndCharacter (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:3742:16)
    at Object.formatDiagnosticsWithColorAndContext (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:55575:59)
    at reportDiagnosticWithColorAndContext (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:58771:25)
    at reportDiagnostic (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:58733:9)
    at reportDiagnostics (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:58738:13)
    at compileProgram (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:59099:13)
    at compile (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:59051:26)
    at performCompilation (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:58940:33)
    at Object.executeCommandLine (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:58883:9)
    at Object.<anonymous> (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/lib/tsc.js:59241:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/bjorn/projects/my-nextjs-typescript-boilerplate/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

project state

cevek commented 7 years ago

@BjornMelgaard Actually it is not same error, because this is common error throws when something happened incorrectly. You can see different stack trace. So you need create new issue.

adz5a commented 7 years ago

Hello, @cevek , you are totally right. It's not the same issue and from the comment of @BjornMelgaard it seems to come from the pretty option ( I just did a quick test and removing the option fixes the problem ). I'll open another issue.

srghma commented 7 years ago

@adz5a @cevek wow, thanks for quick reply

spencerhakim commented 7 years ago

Just started to experiment with gradually converting a Babel+Flow project to TypeScript (possibly relevant?), and I'm hitting this error in v2.5.2.

$PWD/node_modules/typescript/lib/tsc.js:24702
            ts.Debug.assert(targets === undefined || sources.length === targets.length);
                     ^
Error: Debug Failure. False expression.
    at createTypeMapper ($PWD/node_modules/typescript/lib/tsc.js:24702:22)
    at createSignatureInstantiation ($PWD/node_modules/typescript/lib/tsc.js:23498:52)
    at getSignatureInstantiation ($PWD/node_modules/typescript/lib/tsc.js:23493:56)
    at $PWD/node_modules/typescript/lib/tsc.js:22025:97
    at Object.sameMap ($PWD/node_modules/typescript/lib/tsc.js:472:34)
    at getInstantiatedConstructorsForTypeArguments ($PWD/node_modules/typescript/lib/tsc.js:22025:23)
    at resolveCallExpression ($PWD/node_modules/typescript/lib/tsc.js:30643:48)
    at resolveSignature ($PWD/node_modules/typescript/lib/tsc.js:30850:28)
    at getResolvedSignature ($PWD/node_modules/typescript/lib/tsc.js:30870:26)
    at checkCallExpression ($PWD/node_modules/typescript/lib/tsc.js:30913:29)
    at checkExpressionWorker ($PWD/node_modules/typescript/lib/tsc.js:32218:28)
    at checkExpression ($PWD/node_modules/typescript/lib/tsc.js:32162:42)
    at checkExpressionStatement ($PWD/node_modules/typescript/lib/tsc.js:33912:13)
    at checkSourceElement ($PWD/node_modules/typescript/lib/tsc.js:35434:28)
    at Object.forEach ($PWD/node_modules/typescript/lib/tsc.js:275:30)
    at checkBlock ($PWD/node_modules/typescript/lib/tsc.js:33588:16)
    at checkSourceElement ($PWD/node_modules/typescript/lib/tsc.js:35430:28)
    at checkConstructorDeclaration ($PWD/node_modules/typescript/lib/tsc.js:32616:13)
    at checkSourceElement ($PWD/node_modules/typescript/lib/tsc.js:35383:28)
    at Object.forEach ($PWD/node_modules/typescript/lib/tsc.js:275:30)
    at checkClassDeclaration ($PWD/node_modules/typescript/lib/tsc.js:34534:16)
    at checkSourceElement ($PWD/node_modules/typescript/lib/tsc.js:35467:28)
    at Object.forEach ($PWD/node_modules/typescript/lib/tsc.js:275:30)
    at checkSourceFileWorker ($PWD/node_modules/typescript/lib/tsc.js:35536:20)
    at checkSourceFile ($PWD/node_modules/typescript/lib/tsc.js:35521:13)
    at Object.forEach ($PWD/node_modules/typescript/lib/tsc.js:275:30)
    at getDiagnosticsWorker ($PWD/node_modules/typescript/lib/tsc.js:35586:16)
    at getDiagnostics ($PWD/node_modules/typescript/lib/tsc.js:35563:24)
    at Object.getEmitResolver ($PWD/node_modules/typescript/lib/tsc.js:18561:13)
    at emitWorker ($PWD/node_modules/typescript/lib/tsc.js:56075:69)
    at $PWD/node_modules/typescript/lib/tsc.js:56051:66
    at runWithCancellationToken ($PWD/node_modules/typescript/lib/tsc.js:56129:24)
    at Object.emit ($PWD/node_modules/typescript/lib/tsc.js:56051:20)
    at compileProgram ($PWD/node_modules/typescript/lib/tsc.js:59097:38)
    at compile ($PWD/node_modules/typescript/lib/tsc.js:59051:26)
    at performCompilation ($PWD/node_modules/typescript/lib/tsc.js:58940:33)
    at Object.executeCommandLine ($PWD/node_modules/typescript/lib/tsc.js:58883:9)
    at Object.<anonymous> ($PWD/node_modules/typescript/lib/tsc.js:59241:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> ($PWD/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./build",
    "target": "es2017",
    "module": "none",
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "isolatedModules": true,
    "allowJs": true,
    "checkJs": false
  },
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "./src/graphql/**/*"
  ]
}
mhegazy commented 7 years ago

@spencerhakim can you give typescript@next a try an let us know if you see the same crash? also can you share the project where this issue happens? we would be happy to sign any NDA required to get access to the sources. also you could fire the compiler under node --inspect-brk node_modules/typescript/lib/tsc.js --p <tsconfig.json> and at the location of the crash, in checkCallExpression on the stack, get call getSourceFileOfNode(node) and that should tell you the file where the compiler is crashing, and inspecting the node should give you the position and the call target, so you can narrow down the source of the crash, and hopefully be able to reduce the repro.

spencerhakim commented 7 years ago

@mhegazy Thanks for the node --inspect-brk suggestion, it did help me narrow down the issue and recreate it, so here you go: https://github.com/spencerhakim/ts-18254. From what little I understand of tsc's internals and what I could see in the inspector, I think the issue might be with trying to parse Flow's constrained/bound generics.

Not sure if I should complain about this here or if it qualifies as a separate issue, but I'm not sure why tsc is parsing my JS files at all; checkJs is false by default, and this is not at all the behavior I'd expect to see from that option. Additionally, isolatedModules is described as being similar to ts.transpileModule (which bypasses type-checking and transpiles files individually), but that clearly isn't happening here, so I'm confused as to what the option actually does if not that.

sandersn commented 7 years ago

@spencerhakim Yep, flow uses : instead of extends and Typescript parses class B<T: BaseA> as class B<T, BaseA>. Note that this doesn't repro for me with 2.4.2, so it's a recent regression. I'll keep looking to see how the bogus, extra type parameter crashes the compiler.

Your tsconfig has "allowJs": true, which provides basic support for using .js with Typescript. "checkJs": true just reports errors in .js files.

sandersn commented 7 years ago

Here's what causes the crash: when ask for the constructors of a superclass, there is a special case for Javascript code that allows fewer type arguments than there are type parameters. Typescript's super only sees constructors with fewer type parameters than those provided by the base class.

Later, when instantiating the construct signatures, there is a function fillMissingTypeArguments that fills in defaults for type parameters that don't have matching type arguments, including defaults for Javascript subclasses that don't provide enough type arguments. However, the Javascript case never fires because the caller forgets to tell fillMissingTypeArguments that the signature comes from a Javascript file.

It's a pretty simple fix. I'll have a PR up first thing tomorrow.

sandersn commented 7 years ago

Fix is up at #18440