@@ -325,8 +325,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
325
325
}
326
326
}
327
327
328
- w.Local ? tempLocalForType;
329
-
330
328
void setupParamLocal (VariableDeclaration variable, int index,
331
329
Constant ? defaultValue, bool isRequired) {
332
330
w.Local local = paramLocals[implicitParams + index];
@@ -362,9 +360,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
362
360
}
363
361
if (! translator.options.omitImplicitTypeChecks) {
364
362
if (variable.isCovariantByClass || variable.isCovariantByDeclaration) {
365
- final typeLocal = tempLocalForType ?? = addLocal (
366
- translator.classInfo[translator.typeClass]! .nonNullableType);
367
-
368
363
final boxedType = variable.type.isPotentiallyNullable
369
364
? translator.topInfo.nullableType
370
365
: translator.topInfo.nonNullableType;
@@ -379,9 +374,8 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
379
374
_generateArgumentTypeCheck (
380
375
variable.name! ,
381
376
() => b.local_get (operand),
382
- () => types. makeType ( this , variable.type) ,
377
+ variable.type,
383
378
operand,
384
- typeLocal,
385
379
);
386
380
}
387
381
}
@@ -3348,11 +3342,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3348
3342
// Local for the argument.
3349
3343
final argLocal = addLocal (translator.topInfo.nullableType);
3350
3344
3351
- // Local for the expected type of the argument.
3352
- final typeType =
3353
- translator.classInfo[translator.typeClass]! .nonNullableType;
3354
- final argTypeLocal = addLocal (typeType);
3355
-
3356
3345
final member_ = member;
3357
3346
DartType paramType;
3358
3347
if (member_ is Field ) {
@@ -3361,13 +3350,14 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3361
3350
paramType = (member_ as Procedure ).setterType;
3362
3351
}
3363
3352
3364
- _generateArgumentTypeCheck (
3365
- member.name.text,
3366
- () => b.local_get (positionalArgLocal),
3367
- () => types.makeType (this , paramType),
3368
- argLocal,
3369
- argTypeLocal,
3370
- );
3353
+ if (! translator.options.omitImplicitTypeChecks) {
3354
+ _generateArgumentTypeCheck (
3355
+ member.name.text,
3356
+ () => b.local_get (positionalArgLocal),
3357
+ paramType,
3358
+ argLocal,
3359
+ );
3360
+ }
3371
3361
3372
3362
ClassInfo info = translator.classInfo[member_.enclosingClass]! ;
3373
3363
if (member_ is Field ) {
@@ -3465,14 +3455,10 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3465
3455
final List <VariableDeclaration > memberPositionalParams =
3466
3456
procedure.function.positionalParameters;
3467
3457
3468
- // Local for the current argument being checked. Used to avoid indexing the
3469
- // positional parameters array again when throwing type error.
3458
+ // Local for the current argument being checked. Used to avoid indexing
3459
+ // the positional parameters array again when throwing type error.
3470
3460
final argLocal = addLocal (translator.topInfo.nullableType);
3471
3461
3472
- // Local for the expected type of the current positional arguments. Used to
3473
- // avoid generating the type again when throwing type error.
3474
- final argTypeLocal = addLocal (typeType);
3475
-
3476
3462
for (int positionalParamIdx = 0 ;
3477
3463
positionalParamIdx < memberPositionalParams.length;
3478
3464
positionalParamIdx += 1 ) {
@@ -3484,11 +3470,8 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3484
3470
b.i32_const (positionalParamIdx);
3485
3471
b.array_get (translator.nullableObjectArrayType);
3486
3472
},
3487
- () {
3488
- types.makeType (this , param.type);
3489
- },
3473
+ param.type,
3490
3474
argLocal,
3491
- argTypeLocal,
3492
3475
);
3493
3476
}
3494
3477
@@ -3519,11 +3502,8 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3519
3502
b.i32_const (mapNamedParameterToArrayIndex (param.name! ));
3520
3503
b.array_get (translator.nullableObjectArrayType);
3521
3504
},
3522
- () {
3523
- types.makeType (this , param.type);
3524
- },
3505
+ param.type,
3525
3506
argLocal,
3526
- argTypeLocal,
3527
3507
);
3528
3508
}
3529
3509
}
@@ -3582,39 +3562,42 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
3582
3562
/// Does not expect any values on stack and does not leave any values on
3583
3563
/// stack.
3584
3564
///
3585
- /// Locals [argLocal] and [argExpectedTypeLocal] are used to store values
3586
- /// pushed by [pushArg] and [pushArgExpectedType] and reuse the values.
3565
+ /// Locals [argLocal] are used to store values pushed by [pushArg]
3566
+ /// and reuse the values.
3587
3567
///
3588
3568
/// [argName] is used in the type error as the name of the argument that
3589
3569
/// doesn't match the expected type.
3590
3570
void _generateArgumentTypeCheck (
3591
3571
String argName,
3592
3572
void Function () pushArg,
3593
- void Function () pushArgExpectedType ,
3573
+ DartType testedAgainstType ,
3594
3574
w.Local argLocal,
3595
- w.Local argExpectedTypeLocal,
3596
3575
) {
3597
- // Argument
3598
- pushArg ();
3599
- b.local_tee (argLocal);
3600
-
3601
- // Expected type
3602
- pushArgExpectedType ();
3603
- b.local_tee (argExpectedTypeLocal);
3604
-
3605
- // Check that argument type is subtype of expected type
3606
- call (translator.isSubtype.reference);
3607
-
3608
- b.i32_eqz ();
3609
- b.if_ ();
3610
- // Type check failed
3611
- b.local_get (argLocal);
3612
- b.local_get (argExpectedTypeLocal);
3613
- _emitString (argName);
3614
- call (translator.stackTraceCurrent.reference);
3615
- call (translator.throwArgumentTypeCheckError.reference);
3616
- b.unreachable ();
3617
- b.end ();
3576
+ if (translator.options.minify) {
3577
+ // We don't need to include the name in the error message, so we can use
3578
+ // the optimized `as` checks.
3579
+ pushArg ();
3580
+ types.emitAsCheck (
3581
+ this ,
3582
+ testedAgainstType,
3583
+ translator.coreTypes.objectNullableRawType,
3584
+ argLocal.type as w.RefType );
3585
+ b.drop ();
3586
+ } else {
3587
+ pushArg ();
3588
+ b.local_tee (argLocal);
3589
+ types.emitIsTest (
3590
+ this , testedAgainstType, translator.coreTypes.objectNullableRawType);
3591
+ b.i32_eqz ();
3592
+ b.if_ ();
3593
+ b.local_get (argLocal);
3594
+ types.makeType (this , testedAgainstType);
3595
+ _emitString (argName);
3596
+ call (translator.stackTraceCurrent.reference);
3597
+ call (translator.throwArgumentTypeCheckError.reference);
3598
+ b.unreachable ();
3599
+ b.end ();
3600
+ }
3618
3601
}
3619
3602
3620
3603
void _generateTypeArgumentBoundCheck (
0 commit comments