-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Flow analysis failure on "obj is Type == false" #31469
Comments
I believe this is by design. Probably it's best to move this to dotnet/csharplang. |
Apparently there is a discussion on how to fix this kind of syntaxical chaos: The odd thing is that this compiles correcly and 'str' is defined in the else scope instead. if(!(obj is string str))
{
str.Method(); //Use of unassigned local variable 'str'
}
else
{
str.Method(); //Ok
} Language reference
Stack overflow also has a interesting discussion on it. But yes, you are somewhat correct, it is a Roslyn yet a dotnet/csharplang problem at the same time.
|
The language-specified definite assignment rules for |
Issue moved to dotnet/csharplang #2035 via ZenHub |
Version Used:
Multiple tries
Roslyn 2.0 (VS2017) (https://dotnetfiddle.net)
dotnet --version = 3.0.100-preview-009795
Build Engine version 16.0.225-preview+g5ebeba52a1 for .NET Core
Branch master (28 Oct 2018)
https://sharplab.io/#v2:EYLgtghgzgLgpgJwD4AEAMACFBGA3AWACgiUBmLAJgwEEiBvIjJrcnANiwBYMAhAVwDmACgCUjZg0LNpGAPbAAVnADGMOYowBeDACIAEnAA2h2ToLEpMpgEsAZkPkKM1qFmyZYCLdtsRDUODFLK0krKxwATiEdAHkNFwwAO1k1HDQdEXMwjABfcSsjAPyZUOzmSKEAElj41zStDDpPHIzcDAB6dowAUQRZLwBhAGU0bDYAVhAMAFUAuVsMPkToKGsBRLgAEwwTZT8MADcIBGsIYEM4DAByTyvi6Tzg3KIcoA
Steps to Reproduce:
Compile of this code
Expected Behavior:
Code should compile, and print "Obj is string = Hello";
Actual Behavior:
Compiler failure, flow analysis fails
The text was updated successfully, but these errors were encountered: