@@ -28,8 +28,8 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart'
2828 as shared;
2929import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart'
3030 hide MapPatternEntry, RecordPatternField;
31- import 'package:_fe_analyzer_shared/src/type_inference/type_constraint.dart' ;
3231import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart' ;
32+ import 'package:_fe_analyzer_shared/src/type_inference/type_constraint.dart' ;
3333import 'package:_fe_analyzer_shared/src/type_inference/variable_bindings.dart' ;
3434import 'package:_fe_analyzer_shared/src/types/shared_type.dart' ;
3535import 'package:test/test.dart' ;
@@ -1241,6 +1241,46 @@ class Do extends Statement {
12411241 }
12421242}
12431243
1244+ // Represents the entire dot shorthand expression.
1245+ // e.g. `.current.errorZone`
1246+ class DotShorthand extends Expression {
1247+ final Expression expr;
1248+
1249+ DotShorthand ._(this .expr, {required super .location});
1250+
1251+ @override
1252+ void preVisit (PreVisitor visitor) {
1253+ expr.preVisit (visitor);
1254+ }
1255+
1256+ @override
1257+ String toString () => '$expr ' ;
1258+
1259+ @override
1260+ ExpressionTypeAnalysisResult visit (Harness h, SharedTypeSchemaView schema) {
1261+ return h.typeAnalyzer.analyzeDotShorthandExpression (expr, schema);
1262+ }
1263+ }
1264+
1265+ // Represents the head of a dot shorthand.
1266+ // e.g. `.zero`
1267+ class DotShorthandHead extends Expression {
1268+ final String name;
1269+
1270+ DotShorthandHead ._(this .name, {required super .location});
1271+
1272+ @override
1273+ void preVisit (PreVisitor visitor) {}
1274+
1275+ @override
1276+ String toString () => '.$name ' ;
1277+
1278+ @override
1279+ ExpressionTypeAnalysisResult visit (Harness h, SharedTypeSchemaView schema) {
1280+ return h.typeAnalyzer.analyzeDotShorthandHeadExpression (this , name, schema);
1281+ }
1282+ }
1283+
12441284class Equal extends Expression {
12451285 final Expression lhs;
12461286 final Expression rhs;
@@ -2732,6 +2772,23 @@ class MiniAstOperations
27322772 }
27332773 }
27342774
2775+ @override
2776+ TypeConstraintGenerator <Var , Type , String , Node >
2777+ createTypeConstraintGenerator (
2778+ {required TypeConstraintGenerationDataForTesting ?
2779+ typeConstraintGenerationDataForTesting,
2780+ required List <SharedTypeParameterView > typeParametersToInfer,
2781+ required TypeAnalyzerOperations <Var , Type , String >
2782+ typeAnalyzerOperations,
2783+ required bool inferenceUsingBoundsIsEnabled}) {
2784+ return TypeConstraintGatherer ({
2785+ for (var typeParameter in typeParametersToInfer)
2786+ typeParameter
2787+ .unwrapTypeParameterViewAsTypeParameterStructure <TypeParameter >()
2788+ .name
2789+ });
2790+ }
2791+
27352792 /// Returns the downward inference result of a type with the given [name] ,
27362793 /// in the [context] . For example infer `List<int>` from `Iterable<int>` .
27372794 Type downwardInfer (String name, Type context) {
@@ -3181,23 +3238,6 @@ class MiniAstOperations
31813238 Type withNullabilitySuffixInternal (Type type, NullabilitySuffix modifier) {
31823239 return type.withNullability (modifier);
31833240 }
3184-
3185- @override
3186- TypeConstraintGenerator <Var , Type , String , Node >
3187- createTypeConstraintGenerator (
3188- {required TypeConstraintGenerationDataForTesting ?
3189- typeConstraintGenerationDataForTesting,
3190- required List <SharedTypeParameterView > typeParametersToInfer,
3191- required TypeAnalyzerOperations <Var , Type , String >
3192- typeAnalyzerOperations,
3193- required bool inferenceUsingBoundsIsEnabled}) {
3194- return TypeConstraintGatherer ({
3195- for (var typeParameter in typeParametersToInfer)
3196- typeParameter
3197- .unwrapTypeParameterViewAsTypeParameterStructure <TypeParameter >()
3198- .name
3199- });
3200- }
32013241}
32023242
32033243/// Representation of an expression or statement in the pseudo-Dart language
@@ -3386,46 +3426,6 @@ class ObjectPattern extends Pattern {
33863426 }
33873427}
33883428
3389- // Represents the head of a dot shorthand.
3390- // e.g. `.zero`
3391- class DotShorthandHead extends Expression {
3392- final String name;
3393-
3394- DotShorthandHead ._(this .name, {required super .location});
3395-
3396- @override
3397- void preVisit (PreVisitor visitor) {}
3398-
3399- @override
3400- String toString () => '.$name ' ;
3401-
3402- @override
3403- ExpressionTypeAnalysisResult visit (Harness h, SharedTypeSchemaView schema) {
3404- return h.typeAnalyzer.analyzeDotShorthandHeadExpression (this , name, schema);
3405- }
3406- }
3407-
3408- // Represents the entire dot shorthand expression.
3409- // e.g. `.current.errorZone`
3410- class DotShorthand extends Expression {
3411- final Expression expr;
3412-
3413- DotShorthand ._(this .expr, {required super .location});
3414-
3415- @override
3416- void preVisit (PreVisitor visitor) {
3417- expr.preVisit (visitor);
3418- }
3419-
3420- @override
3421- String toString () => '$expr ' ;
3422-
3423- @override
3424- ExpressionTypeAnalysisResult visit (Harness h, SharedTypeSchemaView schema) {
3425- return h.typeAnalyzer.analyzeDotShorthandExpression (expr, schema);
3426- }
3427- }
3428-
34293429class ParenthesizedExpression extends Expression {
34303430 final Expression expr;
34313431
@@ -3920,6 +3920,14 @@ mixin ProtoCollectionElement<Self extends ProtoCollectionElement<dynamic>> {
39203920/// variable).
39213921mixin ProtoExpression
39223922 implements ProtoStatement <Expression >, ProtoCollectionElement <Expression > {
3923+ /// If `this` is an expression `x` , creates a dot shorthand wrapper around
3924+ /// `x` .
3925+ Expression get dotShorthand {
3926+ var location = computeLocation ();
3927+ return new DotShorthand ._(asExpression (location: location),
3928+ location: location);
3929+ }
3930+
39233931 /// If `this` is an expression `x` , creates the expression `x!` .
39243932 Expression get nonNullAssert {
39253933 var location = computeLocation ();
@@ -3933,14 +3941,6 @@ mixin ProtoExpression
39333941 return new Not ._(asExpression (location: location), location: location);
39343942 }
39353943
3936- /// If `this` is an expression `x` , creates a dot shorthand wrapper around
3937- /// `x` .
3938- Expression get dotShorthand {
3939- var location = computeLocation ();
3940- return new DotShorthand ._(asExpression (location: location),
3941- location: location);
3942- }
3943-
39443944 /// If `this` is an expression `x` , creates the expression `(x)` .
39453945 Expression get parenthesized {
39463946 var location = computeLocation ();
@@ -5560,6 +5560,19 @@ class _MiniAstTypeAnalyzer
55605560 flow.doStatement_end (condition);
55615561 }
55625562
5563+ ExpressionTypeAnalysisResult analyzeDotShorthandExpression (
5564+ Expression expression, SharedTypeSchemaView schema) {
5565+ var type = analyzeDotShorthand (expression, schema);
5566+ return new ExpressionTypeAnalysisResult (type: type);
5567+ }
5568+
5569+ ExpressionTypeAnalysisResult analyzeDotShorthandHeadExpression (
5570+ Expression node, String name, SharedTypeSchemaView schema) {
5571+ _irBuilder.atom (name, Kind .expression, location: node.location);
5572+ return new ExpressionTypeAnalysisResult (
5573+ type: SharedTypeView (getDotShorthandContext ().unwrapTypeSchemaView ()));
5574+ }
5575+
55635576 void analyzeExpressionStatement (Expression expression) {
55645577 analyzeExpression (expression, operations.unknownType);
55655578 }
@@ -5645,19 +5658,6 @@ class _MiniAstTypeAnalyzer
56455658 return new ExpressionTypeAnalysisResult (type: SharedTypeView (nullType));
56465659 }
56475660
5648- ExpressionTypeAnalysisResult analyzeDotShorthandHeadExpression (
5649- Expression node, String name, SharedTypeSchemaView schema) {
5650- _irBuilder.atom (name, Kind .expression, location: node.location);
5651- return new ExpressionTypeAnalysisResult (
5652- type: SharedTypeView (getDotShorthandContext ().unwrapTypeSchemaView ()));
5653- }
5654-
5655- ExpressionTypeAnalysisResult analyzeDotShorthandExpression (
5656- Expression expression, SharedTypeSchemaView schema) {
5657- var type = analyzeDotShorthand (expression, schema);
5658- return new ExpressionTypeAnalysisResult (type: type);
5659- }
5660-
56615661 ExpressionTypeAnalysisResult analyzeParenthesizedExpression (
56625662 Expression node, Expression expression, SharedTypeSchemaView schema) {
56635663 var type = analyzeExpression (expression, schema);
0 commit comments