@@ -536,7 +536,13 @@ class GenericFunctionType extends AbstractFunctionType {
536
536
return _typeFormals = _typeFormalsFromFunction (_instantiateTypeParts);
537
537
}
538
538
539
- checkBounds (List typeArgs) {
539
+ /// Checks that [typeArgs] satisfies the upper bounds of the [typeFormals] ,
540
+ /// and throws a [TypeError] if they do not.
541
+ void checkBounds (List typeArgs) {
542
+ // If we don't have explicit type parameter bounds, the bounds default to
543
+ // a top type, so there's nothing to check here.
544
+ if (_instantiateTypeBounds == null ) return ;
545
+
540
546
var bounds = instantiateTypeBounds (typeArgs);
541
547
var typeFormals = this .typeFormals;
542
548
for (var i = 0 ; i < typeArgs.length; i++ ) {
@@ -554,11 +560,12 @@ class GenericFunctionType extends AbstractFunctionType {
554
560
var boundsFn = _instantiateTypeBounds;
555
561
if (boundsFn == null ) {
556
562
// The Dart 1 spec says omitted type parameters have an upper bound of
557
- // Object. However strong mode assumes `dynamic` for all purposes
558
- // (such as instantiate to bounds) so we use that here.
563
+ // Object. However Dart 2 uses `dynamic` for the purpose of instantiate to
564
+ // bounds, so we use that here.
559
565
return List .filled (formalCount, _dynamic);
560
566
}
561
- // If bounds are recursive, we need to apply type formals and return them.
567
+ // Bounds can be recursive or depend on other type parameters, so we need to
568
+ // apply type arguments and return the resulting bounds.
562
569
return JS ('List' , '#.apply(null, #)' , boundsFn, typeArgs);
563
570
}
564
571
@@ -738,10 +745,11 @@ getFunctionTypeMirror(AbstractFunctionType type) {
738
745
bool isType (obj) => JS ('' , '#[#] === #' , obj, _runtimeType, Type );
739
746
740
747
void checkTypeBound (type, bound, name) {
748
+ // TODO(jmesserly): we've optimized `is`/`as`/implicit type checks, it would
749
+ // be nice to have similar optimizations for the subtype relation.
741
750
if (JS ('!' , '#' , isSubtype (type, bound))) return ;
742
751
743
- throwTypeError ('type `$type ` does not extend `$bound `'
744
- ' of `$name `.' );
752
+ throwTypeError ('type `$type ` does not extend `$bound ` of `$name `.' );
745
753
}
746
754
747
755
String typeName (type) => JS ('' , '''(() => {
0 commit comments