Skip to content
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

Use correct get / set inside ref safety analysis #73842

Merged
merged 26 commits into from
Jul 12, 2024
Merged

Conversation

jaredpar
Copy link
Member

@jaredpar jaredpar commented Jun 4, 2024

This fixes a few cases where our code looked at the wrong accessor when doing ref safety analysis.

closes #35606
closes #73550
related #73872
related dotnet/csharplang#8253

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 4, 2024
This code path for checking the receiver is unnecessary. The receiver is
included in `escapeArguments` below where the same check happens.

Added a test that hit the old code path and failed and verified it still
fails after this change.

closes dotnet#73550
@@ -409,10 +518,12 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
switch (expr.Kind)
{
case BoundKind.PropertyGroup:
expr = BindIndexedPropertyAccess((BoundPropertyGroup)expr, mustHaveAllOptionalParameters: false, diagnostics: diagnostics);
if (expr is BoundIndexerAccess indexerAccess)
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this inside { ... } blocks as it's now declaring variables.

@@ -2474,17 +2615,6 @@ private static string GetInvocationParameterName(ParameterSymbol? parameter)
Error(diagnostics, errorCode, syntax, symbol, parameterName);
}

private bool UseUpdatedEscapeRulesForInvocation(Symbol symbol)
Copy link
Member Author

@jaredpar jaredpar Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to MethodInfo.UseUpdatedEscapeRules

// https://github.com/dotnet/roslyn/issues/73550:
// We do not have a test that demonstrates that the statement below makes a difference.
// If it is commented out, not a single test fails
escapeTo = GetValEscape(receiverOpt, scopeOfTheContainingExpression);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is indeed unnecessary. Thinking through the check for IsReceiverRefReadOnly is what caused me to dig into the get / set issues with indexers though.

@@ -1961,21 +2091,6 @@ bool isRefEscape
return escapeScope;
}

private static bool ReturnsRefToRefStruct(Symbol symbol)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to MethodInfo.ReturnsRefToRefStruct

@jaredpar jaredpar marked this pull request as ready for review June 13, 2024 04:33
@jaredpar jaredpar requested a review from a team as a code owner June 13, 2024 04:33
@jaredpar
Copy link
Member Author

@dotnet/roslyn-compiler PTAL

1 similar comment
@jaredpar
Copy link
Member Author

@dotnet/roslyn-compiler PTAL

cston
cston previously approved these changes Jun 15, 2024
Copy link
Member

@cston cston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions, but nothing blocking.

@jaredpar
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jaredpar jaredpar requested a review from a team as a code owner July 12, 2024 11:41
@jaredpar jaredpar merged commit 5c77803 into dotnet:main Jul 12, 2024
28 checks passed
@jaredpar jaredpar deleted the ref-fix branch July 12, 2024 17:07
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 12, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
5 participants