Method type inference should make inference from explicit lambda return type#56534
Method type inference should make inference from explicit lambda return type#56534cston merged 4 commits intodotnet:mainfrom
Conversation
| var delegateReturnType = delegateInvokeMethod.ReturnTypeWithAnnotations; | ||
| if (!delegateReturnType.HasType) | ||
| { | ||
| return; |
| { | ||
| var invokeMethod = n.DelegateInvokeMethod; | ||
| return invokeMethod.Parameters.SequenceEqual(l.Parameters, | ||
| return invokeMethod!.Parameters.SequenceEqual(l.Parameters, |
There was a problem hiding this comment.
An assert seems redundant since the dereference will fail at runtime regardless.
There was a problem hiding this comment.
An assert seems redundant since the dereference will fail at runtime regardless.
I think we prefer using asserts to inform nullable analysis about expectations rather than suppressing diagnostics with !.
There was a problem hiding this comment.
Chuck swayed me on this in some previous PR, but I don't think we circled back to Jared to update guidelines. If the code would clearly crash, then a suppression seems fine to me (assertion wouldn't add much).
Chuck, let's bring this up to team meeting or with Jared to confirm and capture.
| static void F2<T>(Expression<Func<T, T>> x, T y) { Console.WriteLine(x.GetType()); } | ||
| static void Main() | ||
| { | ||
| F1(int (i) => i, (object)1); |
| // (see https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-06-21.md). | ||
| [WorkItem(54257, "https://github.com/dotnet/roslyn/issues/54257")] | ||
| [Fact] | ||
| public void TypeInference_ExplicitReturnType_06() |
|
Done with review pass (commit 1) |
|
|
||
| comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(expectedDiagnostics); | ||
| } |
There was a problem hiding this comment.
Consider adding a test with the explicit return type having a nullable annotation #Resolved
|
@cston Thanks for the spec sections in OP. Are you copying those back into the feature spec as well? |
|
Update "type inference" to make an exact inference from an explicit lambda return type.
Proposed spec changes in bold:
See LDM notes.
Fixes #54257
Relates to test plan #52192