Skip to content

non-null assertions break CFA #36958

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
falsandtru opened this issue Feb 22, 2020 · 3 comments · Fixed by #41075
Closed

non-null assertions break CFA #36958

falsandtru opened this issue Feb 22, 2020 · 3 comments · Fixed by #41075
Labels
Bug A bug in TypeScript Domain: Control Flow The issue relates to control flow analysis Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Milestone

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Feb 22, 2020

TypeScript Version: 3.7.x-dev.20200221

Search Terms:

Code

const m = ''.match('');
m?.[0] && m[0];
m?.[0]! && m[0];
m?.[0].length! > 0 && m[0];
m?.[0].split('').slice() && m[0];
m?.[0].split('')!.slice() && m[0];

Expected behavior:

const m = ''.match('');
m?.[0] && m[0]; // ok
m?.[0]! && m[0]; // ok
m?.[0].length! > 0 && m[0]; // ok
m?.[0].split('').slice() && m[0]; // ok
m?.[0].split('')!.slice() && m[0]; // ok

Actual behavior:

const m = ''.match('');
m?.[0] && m[0]; // ok
m?.[0]! && m[0]; // error
m?.[0].length! > 0 && m[0]; // error
m?.[0].split('').slice() && m[0]; // ok
m?.[0].split('')!.slice() && m[0]; // error

Playground Link: http://www.typescriptlang.org/play/index.html?ts=3.9.0-dev.20200221&ssl=5&ssc=34&pln=4&pc=28#code/MYewdgzgLgBAtjAvDA5CgdHAhlYALACjQEoBuAKDgH50BtABgF0YAyF+Bxi6upgQlbs4nbjU7oANgFMwAcyh4BAPhj1BHJqN6N0EAA4SAllCIpiuo8CkFi64Zspimug8dPE+Fw1Zt2RQA

Related Issues:

@falsandtru
Copy link
Contributor Author

falsandtru commented Feb 22, 2020

cc @DanielRosenwasser @rbuckton

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 26, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 26, 2020
@macabeus
Copy link

macabeus commented Mar 4, 2020

What is CFA?

@DanielRosenwasser
Copy link
Member

control flow analysis

@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Domain: Control Flow The issue relates to control flow analysis labels Mar 4, 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 Domain: Control Flow The issue relates to control flow analysis Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants