Created
June 5, 2020 12:01
-
-
Save thomaslevesque/4317d8562dc47cdfef499a12d1d214ac to your computer and use it in GitHub Desktop.
Repro for CS8762 false positive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics.CodeAnalysis; | |
namespace TestNullable | |
{ | |
class Test | |
{ | |
static bool TrySomething1(string s, [NotNullWhen(false)] out string? failReason) | |
{ | |
// warning CS8762: Parameter 'failReason' must have a non-null value when exiting with 'false'. | |
return s.Length % 2 == 0 | |
? Foo(s, out failReason) | |
: Bar(s, out failReason); | |
} | |
static bool TrySomething2(string s, [NotNullWhen(false)] out string? failReason) | |
{ | |
// no warning | |
if (s.Length % 2 == 0) | |
{ | |
return Foo(s, out failReason); | |
} | |
else | |
{ | |
return Bar(s, out failReason); | |
} | |
} | |
static bool Foo(string s, [NotNullWhen(false)] out string? failReason) | |
{ | |
// Actual implementation not relevant | |
failReason = null; | |
return true; | |
} | |
static bool Bar(string s, [NotNullWhen(false)] out string? failReason) | |
{ | |
// Actual implementation not relevant | |
failReason = null; | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment