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
Lambda expressions in an array initializer are not checked against the new target type of the lambda expression. Instead, the type from initial binding is used, and (improperly) feeds into inference.
[Fact,WorkItem(35302,"https://github.com/dotnet/roslyn/issues/35302")]publicvoidCheckLambdaInArrayInitializer_02(){varsource=@"using System;class C{ static void G(object? o, string s) { if (o == null) return; var f = M(o); _ = f /*T:System.Func<object!>!*/; var fa3 = new[] { f, () => null, // 1 () => { s = null; // 2 return null; // 3 }, }; _ = fa3 /*T:System.Func<object!>![]!*/; fa3[0]().ToString(); } static Func<T> M<T>(T t) => () => t;}";varcomp= CreateCompilation(new[]{ source }, options: WithNonNullTypesTrue());
comp.VerifyTypes();
comp.VerifyDiagnostics(// (12,19): warning CS8603: Possible null reference return.// () => null, // 1
Diagnostic(ErrorCode.WRN_NullReferenceReturn,"null").WithLocation(12,19),// (14,25): warning CS8600: Converting null literal or possible null value to non-nullable type.// s = null; // 2
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable,"null").WithLocation(14,25),// (15,28): warning CS8603: Possible null reference return.// return null; // 3
Diagnostic(ErrorCode.WRN_NullReferenceReturn,"null").WithLocation(15,28));}
There may be similar issues in method type inference, ?:, switch expressions, etc.
The text was updated successfully, but these errors were encountered:
Lambda expressions in an array initializer are not checked against the new target type of the lambda expression. Instead, the type from initial binding is used, and (improperly) feeds into inference.
There may be similar issues in method type inference,
?:
, switch expressions, etc.The text was updated successfully, but these errors were encountered: