From 27f18db214d4f6f4b602d1abc7de95a67c5eedc5 Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Tue, 8 Apr 2025 07:18:41 -0700 Subject: [PATCH] [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 Commit-Queue: Kallen Tu --- .../src/type_inference/inference_visitor.dart | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor.dart b/pkg/front_end/lib/src/type_inference/inference_visitor.dart index 29a259f2dc4..8e9262e243d 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor.dart @@ -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); } }