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
{{ message }}
Repository navigation
Unexpected nullability warning is reported for erroneous conditional assignment #72912
[Fact]
public void Test()
{
string source = @"
#nullable enable
public class C
{
public static void Main()
{
C2? c = null;
var a = c ??= ""2"";
Print(a);
}
static void Print(dynamic b)
{
}
}
class C2 {}
";
var comp = CreateCompilation(source, options: TestOptions.DebugExe, targetFramework: TargetFramework.StandardAndCSharp);
comp.VerifyDiagnostics(
// (9,17): error CS0019: Operator '??=' cannot be applied to operands of type 'C2' and 'string'
// var a = c ??= "2";
Diagnostic(ErrorCode.ERR_BadBinaryOps, @"c ??= ""2""").WithArguments("??=", "C2", "string").WithLocation(9, 17),
// (9,23): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'C2'.
// var a = c ??= "2";
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, @"""2""").WithArguments("string", "C2").WithLocation(9, 23)
);
}
The nullability warning doesn't really make sense. The nullability actually matches, the types are different though.
Activity
AlekseyTs commentedon Apr 6, 2024
CC @333fred
Restore `dynamic` as result type of some operations involving `dynami…
Restore `dynamic` as result type of some operations involving `dynami…
Port #72964 to release/dev17.10 (#73058)