-
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
Fix asserts when emitting calls with optional byref parameters #72203
Conversation
@@ -497,13 +497,13 @@ private BoundExpression MakeCallWithNoExplicitArgument(MethodArgumentInfo method | |||
if (method.IsExtensionMethod) | |||
{ | |||
Debug.Assert(expression == null); | |||
Debug.Assert(method.Parameters.AsSpan()[1..].All(assertParametersAreOptional, (p, assertOptional) => (p.IsOptional || p.IsParams || !assertOptional) && p.RefKind == RefKind.None)); | |||
Debug.Assert(method.ParameterRefKinds.IsDefaultOrEmpty || method.ParameterRefKinds[0] is RefKind.In or RefKind.RefReadOnlyParameter or RefKind.None); | |||
Debug.Assert(method.Parameters.AsSpan()[1..].All(assertParametersAreOptional, static (p, assertOptional) => (p.IsOptional || p.IsParams || !assertOptional) && p.RefKind is RefKind.None or RefKind.In or RefKind.RefReadOnlyParameter)); |
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.
We will not be able to pass a reference to a "real" location to the call
We already warn at the declaration site if a ref readonly parameter has a default value. Also this PR is just fixing asserts, not changing behavior of the compiler in Release builds.
Debug.Assert(method.Parameters.AsSpan()[1..].All(assertParametersAreOptional, (p, assertOptional) => (p.IsOptional || p.IsParams || !assertOptional) && p.RefKind == RefKind.None)); | ||
Debug.Assert(method.ParameterRefKinds.IsDefaultOrEmpty || method.ParameterRefKinds[0] is RefKind.In or RefKind.RefReadOnlyParameter or RefKind.None); | ||
Debug.Assert(method.Parameters.AsSpan()[1..].All(assertParametersAreOptional, static (p, assertOptional) => (p.IsOptional || p.IsParams || !assertOptional) && p.RefKind is RefKind.None or RefKind.In or RefKind.RefReadOnlyParameter)); | ||
Debug.Assert(method.ParameterRefKinds.IsDefaultOrEmpty || method.ParameterRefKinds.All(static refKind => refKind is RefKind.In or RefKind.RefReadOnlyParameter or RefKind.None)); |
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.
{ | ||
public int Current { get; private set; } | ||
public bool MoveNext() => Current++ != 3; | ||
public void Dispose({{modifier}} int x = 5) { Console.Write("D"); } |
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 5)
@dotnet/roslyn-compiler for a second review, thanks |
Discovered while investigating #72004.