Skip to content

Checker crash in isWeakType #38369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue May 6, 2020 · 1 comment · Fixed by #38398
Closed

Checker crash in isWeakType #38369

DanielRosenwasser opened this issue May 6, 2020 · 1 comment · Fixed by #38398
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@DanielRosenwasser
Copy link
Member

Reported by @wycats, but no repro available

TypeError: Cannot read property 'length' of undefined
    at isWeakType (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:42173:48)
    at isRelatedTo (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:40927:58)
    at checkTypeRelatedTo (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:40657:26)
    at isTypeRelatedTo (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:40621:24)
    at isTypeSubtypeOf (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:39909:20)
    at getNarrowedType (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:45275:24)
    at narrowTypeByTypePredicate (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:45295:36)
    at getTypeAtFlowCall (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:44715:61)
    at getTypeAtFlowNode (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:44590:32)
    at getFlowTypeOfReference (/home/wycats/Code/hbs-parser/node_modules/.pnpm/registry.npmjs.org/typescript/4.0.0-dev.20200506/node_modules/typescript/lib/tsc.js:44550:51)
@DanielRosenwasser DanielRosenwasser added the Needs Investigation This issue needs a team member to investigate its status. label May 6, 2020
@DanielRosenwasser DanielRosenwasser self-assigned this May 6, 2020
@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented May 6, 2020

This seems to happen because the evolving array type doesn't have any resolved properties, and we actually check that as a target type when narrowing.

Here's the repro:

export function unsafeCast<T>(_value: unknown): asserts _value is T { }

function yadda() {
    let out = [];

    out.push(100)

    unsafeCast<any>(out);
    return out;
}

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output and removed Needs Investigation This issue needs a team member to investigate its status. labels May 6, 2020
@DanielRosenwasser DanielRosenwasser removed their assignment May 6, 2020
@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants