[cfe] Add FunctionNode.thisVariable

In the new variable model `this` is treate as a variable. Similarly to
other variables, it is placed into a variable context, which is
treated as the point of declaration of `this` variable. Since
parameter lists of a `FunctionNode`, such as
`FunctionNode.positionalParameters` and
`FunctionNode.namedParameters`, aren't treated as declarations either,
but rather as a convenient way to access the parameters, a similar
treatment of `this` variable is introduced in this CL, where it
becomes accessible via `FunctionNode.thisVariable`, in addition to
being declared in an appropriate variable context.

Part of https://github.com/dart-lang/sdk/issues/61572

Change-Id: Ia608fd01661353eb704de225f6b123900b1671b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
This commit is contained in:
Chloe Stefantsova
2026-04-14 04:18:56 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent b43c8e8696
commit c82c4632a1
19 changed files with 98 additions and 6 deletions
+2
View File
@@ -886,6 +886,7 @@ class CloneVisitorNotMembers
.map(clone)
.toList();
List<VariableDeclaration> named = node.namedParameters.map(clone).toList();
VariableDeclaration? thisVariable = cloneOptional(node.thisVariable);
final DartType? futureValueType = node.emittedValueType != null
? visitType(node.emittedValueType!)
: null;
@@ -894,6 +895,7 @@ class CloneVisitorNotMembers
typeParameters: typeParameters,
positionalParameters: positional,
namedParameters: named,
thisVariable: thisVariable,
requiredParameterCount: node.requiredParameterCount,
returnType: visitType(node.returnType),
asyncMarker: node.asyncMarker,
+2
View File
@@ -41,6 +41,7 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer {
int requiredParameterCount;
List<VariableDeclaration> positionalParameters;
List<VariableDeclaration> namedParameters;
VariableDeclaration? thisVariable;
DartType returnType; // Not null.
Statement? _body;
@@ -110,6 +111,7 @@ class FunctionNode extends TreeNode implements ScopeProvider, ContextConsumer {
this.asyncMarker = AsyncMarker.Sync,
AsyncMarker? dartAsyncMarker,
this.emittedValueType,
this.thisVariable,
}) : this.positionalParameters =
positionalParameters ?? <VariableDeclaration>[],
this.requiredParameterCount =
+15
View File
@@ -4367,6 +4367,9 @@ class EquivalenceStrategy {
if (!checkFunctionNode_namedParameters(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
if (!checkFunctionNode_thisVariable(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
if (!checkFunctionNode_returnType(visitor, node, other)) {
result = visitor.resultOnInequivalence;
}
@@ -10832,6 +10835,18 @@ class EquivalenceStrategy {
);
}
bool checkFunctionNode_thisVariable(
EquivalenceVisitor visitor,
FunctionNode node,
FunctionNode other,
) {
return visitor.checkNodes(
node.thisVariable,
other.thisVariable,
'thisVariable',
);
}
bool checkFunctionNode_returnType(
EquivalenceVisitor visitor,
FunctionNode node,