Fix 'GetRefEscape' for invocation using old rules #80261
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #80244
The reason this only pops up when indirecting to a local is: the safe-contexts of a local are calc'd when its initializer is visited, using
GetRefEscape()/GetValEscape(), and are stored. When a usage of the local is found, these safe-contexts are looked up and checked against the context of the usage.Simple cases like
return ref rs[1]don't end up actually usingGetRefEscape()forref rs[1]. Instead it usesCheckRefEscape()only, which uses a completely different code path to check the escape, which correctly understood thatthisdoes not escape by-reference.The
GetRefEscape()path needed to be changed to reflect thatthisdoesn't escape by-reference in the old rules.I saw that the
Check()path also sometimes adjusts theMethodInvocationInfoto drop the receiver in order to visit it separately. This didn't seem necessary here.