@@ -247,10 +247,13 @@ Expression intLiteral(int value, {bool? expectConversionToDouble}) =>
247247 expectConversionToDouble: expectConversionToDouble,
248248 location: computeLocation ());
249249
250- Pattern listPattern (List <Pattern > elements, {String ? elementType}) =>
250+ Pattern listPattern (List <ListPatternElement > elements, {String ? elementType}) =>
251251 _ListPattern (elementType == null ? null : Type (elementType), elements,
252252 location: computeLocation ());
253253
254+ ListPatternElement listPatternRestElement ([Pattern ? pattern]) =>
255+ _RestPatternElement (pattern, location: computeLocation ());
256+
254257Statement localFunction (List <Statement > body) {
255258 var location = computeLocation ();
256259 return _LocalFunction (_Block (body, location: location), location: location);
@@ -685,6 +688,12 @@ class Label extends Node {
685688 String toString () => _name;
686689}
687690
691+ abstract class ListPatternElement implements Node {
692+ void preVisit (PreVisitor visitor, VariableBinder <Node , Var > variableBinder);
693+
694+ String _debugString ({required bool needsKeywordOrType});
695+ }
696+
688697/// Representation of an expression that can appear on the left hand side of an
689698/// assignment (or as the target of `++` or `--` ). Methods in this class may be
690699/// used to create more complex expressions based on this one.
@@ -775,7 +784,13 @@ class MiniAstOperations
775784 'List <: int' : false ,
776785 'List <: Iterable' : true ,
777786 'List <: Object' : true ,
787+ 'List<dynamic> <: Object' : true ,
788+ 'List<Object?> <: Object' : true ,
789+ 'List<int> <: dynamic' : true ,
790+ 'List<int> <: Iterable<double>' : false ,
791+ 'List<int> <: Iterable<int>' : true ,
778792 'List<int> <: List<num>' : true ,
793+ 'List<int> <: String' : false ,
779794 'Never <: int' : true ,
780795 'Never <: int?' : true ,
781796 'Never <: Null' : true ,
@@ -847,6 +862,8 @@ class MiniAstOperations
847862 };
848863
849864 static final Map <String , Type > _coreGlbs = {
865+ 'Object?, double' : Type ('double' ),
866+ 'Object?, int' : Type ('int' ),
850867 'double, int' : Type ('Never' ),
851868 'double?, int?' : Type ('Null' ),
852869 'int?, num' : Type ('int' ),
@@ -1029,12 +1046,22 @@ class MiniAstOperations
10291046 @override
10301047 Type makeNullable (Type type) => lub (type, Type ('Null' ));
10311048
1049+ @override
1050+ Type ? matchIterableType (Type type) {
1051+ if (type is NonFunctionType &&
1052+ type.name == 'Iterable' &&
1053+ type.args.length == 1 ) {
1054+ return type.args[0 ];
1055+ }
1056+ return null ;
1057+ }
1058+
10321059 @override
10331060 Type ? matchListType (Type type) {
1034- if (type is NonFunctionType ) {
1035- if ( type.args.length == 1 ) {
1036- return type.args[ 0 ];
1037- }
1061+ if (type is NonFunctionType &&
1062+ type.name == 'List' &&
1063+ type.args.length == 1 ) {
1064+ return type.args[ 0 ];
10381065 }
10391066 return null ;
10401067 }
@@ -1151,7 +1178,9 @@ class ObjectPatternRequiredType {
11511178 }
11521179}
11531180
1154- abstract class Pattern extends Node with PossiblyGuardedPattern {
1181+ abstract class Pattern extends Node
1182+ with PossiblyGuardedPattern
1183+ implements ListPatternElement {
11551184 Pattern ._({required super .location}) : super ._();
11561185
11571186 Pattern get nullAssert =>
@@ -1180,8 +1209,6 @@ abstract class Pattern extends Node with PossiblyGuardedPattern {
11801209 Pattern or (Pattern other) =>
11811210 _LogicalPattern (this , other, isAnd: false , location: computeLocation ());
11821211
1183- void preVisit (PreVisitor visitor, VariableBinder <Node , Var > variableBinder);
1184-
11851212 RecordPatternField recordField ([String ? name]) {
11861213 return RecordPatternField (
11871214 name: name,
@@ -1206,8 +1233,6 @@ abstract class Pattern extends Node with PossiblyGuardedPattern {
12061233 location: location,
12071234 );
12081235 }
1209-
1210- String _debugString ({required bool needsKeywordOrType});
12111236}
12121237
12131238class PatternVariableJoin extends Var {
@@ -2554,7 +2579,7 @@ class _LabeledStatement extends Statement {
25542579class _ListPattern extends Pattern {
25552580 final Type ? _elementType;
25562581
2557- final List <Pattern > _elements;
2582+ final List <ListPatternElement > _elements;
25582583
25592584 _ListPattern (this ._elementType, this ._elements, {required super .location})
25602585 : super ._();
@@ -3256,6 +3281,11 @@ class _MiniAstTypeAnalyzer
32563281 return null ;
32573282 }
32583283
3284+ @override
3285+ Pattern ? getRestPatternElementPattern (Node element) {
3286+ return element is _RestPatternElement ? element._pattern : null ;
3287+ }
3288+
32593289 @override
32603290 SwitchExpressionMemberInfo <Node , Expression , Var >
32613291 getSwitchExpressionMemberInfo (
@@ -3400,6 +3430,19 @@ class _MiniAstTypeAnalyzer
34003430 _irBuilder.atom ('noop' , Kind .statement, location: node.location);
34013431 }
34023432
3433+ @override
3434+ void handleRestPatternElement (
3435+ Pattern container,
3436+ covariant _RestPatternElement restElement,
3437+ ) {
3438+ if (restElement._pattern != null ) {
3439+ _irBuilder.apply ('...' , [Kind .pattern], Kind .pattern,
3440+ location: restElement.location);
3441+ } else {
3442+ _irBuilder.atom ('...' , Kind .pattern, location: restElement.location);
3443+ }
3444+ }
3445+
34033446 @override
34043447 void handleSwitchScrutinee (Type type) {}
34053448
@@ -3418,6 +3461,11 @@ class _MiniAstTypeAnalyzer
34183461 }
34193462 }
34203463
3464+ @override
3465+ bool isRestPatternElement (Node element) {
3466+ return element is _RestPatternElement ;
3467+ }
3468+
34213469 @override
34223470 bool isSwitchExhaustive (
34233471 covariant _SwitchStatement node, Type expressionType) {
@@ -3852,6 +3900,27 @@ class _RelationalPattern extends Pattern {
38523900 _debugString ({required bool needsKeywordOrType}) => '$operator $operand ' ;
38533901}
38543902
3903+ class _RestPatternElement extends Node implements ListPatternElement {
3904+ final Pattern ? _pattern;
3905+
3906+ _RestPatternElement (this ._pattern, {required super .location}) : super ._();
3907+
3908+ @override
3909+ void preVisit (PreVisitor visitor, VariableBinder <Node , Var > variableBinder) {
3910+ _pattern? .preVisit (visitor, variableBinder);
3911+ }
3912+
3913+ @override
3914+ String _debugString ({required bool needsKeywordOrType}) {
3915+ var pattern = _pattern;
3916+ if (pattern == null ) {
3917+ return '...' ;
3918+ } else {
3919+ return '...${pattern ._debugString (needsKeywordOrType : false )}' ;
3920+ }
3921+ }
3922+ }
3923+
38553924class _Return extends Statement {
38563925 _Return ({required super .location});
38573926
0 commit comments