microsoft / TypeScript

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

Debug failure with dereferenced functions of different arities #30647

Closed wolfgang42 closed 5 years ago

wolfgang42 commented 5 years ago

TypeScript Version: Version 3.4.0-dev.20190329

Search Terms: "debug failure getArgumentArityError"

Code

const s = {
    a: function a(k: string) {
        return k
    },
    b: function b(k: string, l: number) {
        return `${k}:${l}`
    },
}

type AnyFunc = 'a' | 'b'

function c(f: AnyFunc, k: string, ...args: any[]) {
    return s[f](k, ...args)
}

Expected behavior: c() can be called as either c('a', 'foo') or c('b', 'foo', 3) (not necessarily fully type-checked).

Actual behavior: Crash:

$ node_modules/.bin/tsc src/test.ts
C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:72973
                throw e;
                ^

Error: Debug Failure. False expression.
    at Object.first (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:951:15)
    at getArgumentArityError (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:41936:32)
    at resolveCall (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:42023:41)
    at resolveCallExpression (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:42255:20)
    at resolveSignature (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:42494:28)
    at getResolvedSignature (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:42514:26)
    at checkCallExpression (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:42585:29)
    at checkExpressionWorker (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:44393:28)
    at checkExpression (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:44320:38)
    at checkExpressionCached (C:\Users\wfaust\Documents\Development\screeps\node_modules\typescript\lib\tsc.js:44109:38)

Related Issues: Lots of debug failures, but none that seem relevant.

lkho commented 5 years ago

This bug seems to occur only for 3.4.0-dev.20190313 and after, I have tried one by one from 3.4.0-dev.20190329 backwards until that.

[here is a more simple reproducible code](https://www.typescriptlang.org/play/index.html#src=function%20x(a%2C%20b%2C%20c)%20%7B%0D%0A%20%20%20%20return%20%60%24%7Ba%7D%3A%24%7Bb%7D%3A%24%7Bc%7D%60%3B%0D%0A%7D%0D%0A%0D%0Afunction%20y()%20%7B%0D%0A%20%20%20%20return%20x('a'%2C%20...arguments)%3B%0D%0A%7D) You will see NO compiled output since it crashed. Open the browser console to view the Debug Failure. False expression. error.

jkillian commented 5 years ago

@RyanCavanaugh would you consider doing a bugfix release for 3.4.x with #30758 in it instead of waiting for TypeScript 3.5? Just tried to upgrade our codebase to TS 3.4 and was blocked by this issue today.

squirly commented 5 years ago

@RyanCavanaugh Also looking for a response here. This seems to be a bug introduced in 3.4 so it would make sense to patch it before 3.5. This is also blocking the upgrade for a few projects I maintain.

If I open a PR to cherry-pick this commit into the release branch, release-3.4. Would it be accepted?

RyanCavanaugh commented 5 years ago

We can take a PR for 3.4 and see if anything else comes in over the next few days to go along with it