-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
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
Method type inference should make inference from explicit lambda return type #56534
Conversation
var delegateReturnType = delegateInvokeMethod.ReturnTypeWithAnnotations; | ||
if (!delegateReturnType.HasType) | ||
{ | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3003,7 +3003,7 @@ private static bool AreCloseEnough(Symbol original, Symbol updated) | |||
private static bool AreLambdaAndNewDelegateSimilar(LambdaSymbol l, NamedTypeSymbol n) | |||
{ | |||
var invokeMethod = n.DelegateInvokeMethod; | |||
return invokeMethod.Parameters.SequenceEqual(l.Parameters, | |||
return invokeMethod!.Parameters.SequenceEqual(l.Parameters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An assert seems redundant since the dereference will fail at runtime regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// (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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (commit 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 2)
|
||
comp = CreateCompilation(source); | ||
comp.VerifyDiagnostics(expectedDiagnostics); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test with the explicit return type having a nullable annotation #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 2)
@cston Thanks for the spec sections in OP. Are you copying those back into the feature spec as well? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 4)
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