roslyn
roslyn copied to clipboard
Update method invocation escape analysis to match spec changes
Update the C#11 escape analysis rules for method invocation to match the recent spec changes.
For a given argument
a
that is passed to parameterp
:
- If
p
isscoped ref
thena
does not contribute ref-safe-to-escape when considering arguments.- If
p
isscoped
thena
does not contribute safe-to-escape when considering arguments.
A value resulting from a method invocation
e1.M(e2, ...)
is safe-to-escape from the smallest of the following scopes:
- The calling method
- The safe-to-escape contributed by all argument expressions
- When the return is a
ref struct
then ref-safe-to-escape contributed by allref
arguments
A value resulting from a method invocation
ref e1.M(e2, ...)
is ref-safe-to-escape the smallest of the following scopes:
- The safe-to-escape of the rvalue of
e1.M(e2, ...)
- The ref-safe-to-escape contributed by all
ref
arguments
For any method invocation
e.M(a1, a2, ... aN)
- Calculate the safe-to-escape of the method return (for this rule assume it has a
ref struct
return type)- All
ref
orout
arguments ofref struct
types must be assignable by a value with that safe-to-escape. This applies even when theref
argument matches ascoped ref
parameter.
See also https://github.com/dotnet/roslyn/issues/62327.