Skip to content

Parameter escapeFrom in CheckValEscape()/CheckRefEscape() is confusing #80682

@RikkiGibson

Description

@RikkiGibson

internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)

It looks like escapeFrom often has the same value as _localScopeDepth. Possibly, it always has the same value.

In my opinion, escapeFrom is a confusing name for this parameter, as it implies that the safe-context of BoundExpression expr is already known. But, usually that safe-context is actually determined by calling a helper like GetParameterValEscape(...) and passing in expr, as the BoundKind of expr is switched on/narrowed down.

Instead, it seems like escapeFrom is used when the expression is thought to hold a reference to the current block.

It seems like things would be more clear if escapeFrom were either renamed to localScopeDepth a la GetValEscape(), or, if the parameter were deleted and _localScopeDepth were used instead.

Note that theoretically it seems like we could implement our ref safety checks by patterns like GetValEscape(source).IsConvertibleTo(GetValEscape(dest)). The reason we have CheckValEscape methods is, that when the conversion of the source safe-context fails, we can give an error which is appropriate for the particular expression.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions