You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a class method has a never return type (see repro1 function), the control flow analysis ignores this.
When a function method has a never return type (see repro2 function), the control flow analysis correctly identifies that this execution branch will end.
π Expected behavior
I expected that the function and class method would be treated in the same way by the CFA, because I can't find an obvious reason why they should differ.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
A function call is analyzed as an assertion call or never-returning call when
the call occurs as a top-level expression statement, and
the call specifies a single identifier or a dotted sequence of identifiers for the function name, and
each identifier in the function name references an entity with an explicit type, and
the function name resolves to a function type with an asserts return type or an explicit never return type annotation.
Another workaround is as follows:
functionrepro1(arg: string|undefined): number{if(!arg){// compatible with return type because the type is `never`, even if the CFA doesn't workreturnnewClass().throwMethod();}returnarg.length;}
π Search Terms
"control flow analysis", "never return"
π Version & Regression Information
never
β― Playground Link
https://www.typescriptlang.org/play?#code/MYGwhgzhAEDC5WgbwLAChrQC4AsBOA9gO4CyAprgQCYAUAlAFzQB2ZAbmXsupproUWgAiAEZhmAcyEBuHtAC+6RWnQAzAK7NgWAJYFm2fMQBim7Xub0mrDl1QZDA4WMkyl6NWd37oeMgAdCAEYaMDwJJggsPB1JaAAfaE0qMlVYsio6bgcdVWgaAEIwiSz7XhYyQXhICHoAOn5ickpaOlkHZUw-LHU8A2K6kDJJXHblTy1vAz9AggAmUPDI6NiJBKTmFLTWTOzMXPyi8NK5PiMiU0mLenbMTt8KXv7wweGJUfc0IA
π» Code
π Actual behavior
When a class method has a
never
return type (seerepro1
function), the control flow analysis ignores this.When a function method has a
never
return type (seerepro2
function), the control flow analysis correctly identifies that this execution branch will end.π Expected behavior
I expected that the function and class method would be treated in the same way by the CFA, because I can't find an obvious reason why they should differ.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: