We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
[Fact] [WorkItem(33664, "https://github.com/dotnet/roslyn/issues/33664")] public void ConditionalOperator_WithLambdaConversions() { var source = @" using System; class C { Func<bool, T> D1<T>(T t) => k => t; void M1(bool b, string? s) { _ = (b ? D1(s) : k => s) /*T:System.Func<bool, string?>!*/; _ = (b ? k => s : D1(s)) /*T:System.Func<bool, string?>!*/; _ = (true ? D1(s) : k => s) /*T:System.Func<bool, string?>!*/; _ = (true ? k => s : D1(s)) /*T:System.Func<bool, string>!*/; // unexpected type _ = (false ? D1(s) : k => s) /*T:System.Func<bool, string>!*/; // unexpected type _ = (false ? k => s : D1(s)) /*T:System.Func<bool, string?>!*/; _ = (b ? D1(s!) : k => s) /*T:System.Func<bool, string>!*/; // 1, unexpected type _ = (b ? k => s : D1(s!)) /*T:System.Func<bool, string>!*/; // 2, unexpected type _ = (true ? D1(s!) : k => s) /*T:System.Func<bool, string>!*/; // unexpected type _ = (true ? k => s : D1(s!)) /*T:System.Func<bool, string>!*/; // 3, unexpected type _ = (false ? D1(s!) : k => s) /*T:System.Func<bool, string>!*/; // 4, unexpected type _ = (false ? k => s : D1(s!)) /*T:System.Func<bool, string>!*/; // unexpected type _ = (b ? D1(true ? throw null! : s) : k => s) /*T:System.Func<bool, string>!*/; // 5, unexpected type _ = (b ? k => s : D1(true ? throw null! : s)) /*T:System.Func<bool, string>!*/; // 6, unexpected type _ = (true ? D1(true ? throw null! : s) : k => s) /*T:System.Func<bool, string>!*/; // unexpected type _ = (true ? k => s : D1(true ? throw null! : s)) /*T:System.Func<bool, string>!*/; // 7, unexpected type _ = (false ? D1(true ? throw null! : s) : k => s) /*T:System.Func<bool, string>!*/; // 8, unexpected type _ = (false ? k => s : D1(true ? throw null! : s)) /*T:System.Func<bool, string>!*/; // unexpected type } delegate T MyDelegate<T>(bool b); ref MyDelegate<T> D2<T>(T t) => throw null!; void M(bool b, string? s) { _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate<string>!*/; // 9 _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate<string>!*/; // 10 _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate<string>!*/; // 11 _ = (true ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate<string!>!*/; _ = (false ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate<string!>!*/; _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate<string>!*/; // 12 } }"; // See TODO2 // Best type inference involving lambda conversion should agree with method type inference // Missing diagnostics var comp = CreateCompilation(source, options: WithNonNullTypesTrue()); comp.VerifyTypes(); comp.VerifyDiagnostics( // (36,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate<string?>' doesn't match target type 'C.MyDelegate<string>'. // _ = (b ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate<string>!*/; // 9 Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref D2(s) : ref D2(s!)").WithArguments("C.MyDelegate<string?>", "C.MyDelegate<string>").WithLocation(36, 14), // (37,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate<string>' doesn't match target type 'C.MyDelegate<string?>'. // _ = (b ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate<string>!*/; // 10 Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "b ? ref D2(s!) : ref D2(s)").WithArguments("C.MyDelegate<string>", "C.MyDelegate<string?>").WithLocation(37, 14), // (38,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate<string?>' doesn't match target type 'C.MyDelegate<string>'. // _ = (true ? ref D2(s) : ref D2(s!)) /*T:C.MyDelegate<string>!*/; // 11 Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "true ? ref D2(s) : ref D2(s!)").WithArguments("C.MyDelegate<string?>", "C.MyDelegate<string>").WithLocation(38, 14), // (41,14): warning CS8619: Nullability of reference types in value of type 'C.MyDelegate<string>' doesn't match target type 'C.MyDelegate<string?>'. // _ = (false ? ref D2(s!) : ref D2(s)) /*T:C.MyDelegate<string>!*/; // unexpected type Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "false ? ref D2(s!) : ref D2(s)").WithArguments("C.MyDelegate<string>", "C.MyDelegate<string?>").WithLocation(41, 14) ); }
[Fact] public void ReturnTypeInference_DelegateTypes() { var source = @" class C { System.Func<bool, T> D1<T>(T t) => k => t; void M1(bool b, string? s, string s2) { M2(k => s, D1(s)) /*T:System.Func<bool, string?>!*/; M2(D1(s), k => s) /*T:System.Func<bool, string?>!*/; M2(k => s2, D1(s2)) /*T:System.Func<bool, string!>!*/; M2(D1(s2), k => s2) /*T:System.Func<bool, string!>!*/; _ = (new[] { k => s, D1(s) }) /*T:System.Func<bool, string?>![]!*/; _ = (new[] { D1(s), k => s }) /*T:System.Func<bool, string?>![]!*/; _ = (new[] { k => s2, D1(s2) }) /*T:System.Func<bool, string>![]!*/; // wrong _ = (new[] { D1(s2), k => s2 }) /*T:System.Func<bool, string>![]!*/; // wrong } T M2<T>(T x, T y) => throw null!; }"; // See TODO2 // Best type inference involving lambda conversion should agree with method type inference var comp = CreateCompilation(source, options: WithNonNullTypesTrue()); comp.VerifyTypes(); comp.VerifyDiagnostics(); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: