[cfe] Dot Shorthands: Fix bug with property fileOffsets.

Surfaced from this co19 test crashing because of an assert when making a null-aware element. The `fileOffset` for static tearoffs and static gets were not being properly set and caused the crash. This CL simply sets the `fileOffset` on those expressions and existing tests should pass.

https://github.com/dart-lang/co19/blob/2c7f9a6a379cfc49b3e9019d1f616d7ec9edd766/LanguageFeatures/Static-access-shorthand/non_ambiguity_A02_t01.dart

Bug: https://github.com/dart-lang/sdk/issues/59758
Change-Id: I7b81f0ee11d8a9458154f1148e92523d1ad8be99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420840
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
Kallen Tu
2025-04-08 07:18:41 -07:00
committed by Commit Queue
parent e7e07f73aa
commit 27f18db214
@@ -12284,18 +12284,21 @@ class InferenceVisitorImpl extends InferenceVisitorBase
ExpressionInferenceResult expressionInferenceResult;
switch (member) {
case Field():
expressionInferenceResult =
inferExpression(new StaticGet(member), cachedContext);
Expression staticGet = new StaticGet(member)
..fileOffset = node.fileOffset;
expressionInferenceResult = inferExpression(staticGet, cachedContext);
case Procedure():
if (member.isGetter) {
expressionInferenceResult =
inferExpression(new StaticGet(member), cachedContext);
Expression staticGet = new StaticGet(member)
..fileOffset = node.fileOffset;
expressionInferenceResult = inferExpression(staticGet, cachedContext);
} else {
// Method tearoffs.
DartType type =
member.function.computeFunctionType(Nullability.nonNullable);
return instantiateTearOff(
type, typeContext, new StaticTearOff(member));
Expression tearOff = new StaticTearOff(member)
..fileOffset = node.fileOffset;
return instantiateTearOff(type, typeContext, tearOff);
}
case Constructor():
case null:
@@ -12317,13 +12320,15 @@ class InferenceVisitorImpl extends InferenceVisitorBase
if (constructor is Constructor) {
DartType type = constructor.function
.computeFunctionType(Nullability.nonNullable);
return instantiateTearOff(
type, typeContext, new ConstructorTearOff(constructor));
Expression tearOff = new ConstructorTearOff(constructor)
..fileOffset = node.fileOffset;
return instantiateTearOff(type, typeContext, tearOff);
} else if (constructor is Procedure) {
DartType type = constructor.function
.computeFunctionType(Nullability.nonNullable);
return instantiateTearOff(
type, typeContext, new StaticTearOff(constructor));
Expression tearOff = new StaticTearOff(constructor)
..fileOffset = node.fileOffset;
return instantiateTearOff(type, typeContext, tearOff);
}
}