@@ -2992,41 +2992,6 @@ class CodeGenerator extends Object
2992
2992
bool nameType: true ,
2993
2993
bool hoistType: true ,
2994
2994
definite: false }) {
2995
- var parts = _emitFunctionTypeParts (type,
2996
- parameters: parameters,
2997
- lowerTypedef: lowerTypedef,
2998
- nameType: nameType,
2999
- hoistType: hoistType);
3000
- var helper = definite ? 'definiteFunctionType' : 'functionType' ;
3001
- var fullType = _callHelper ('${helper }(#)' , [parts]);
3002
- if (! nameType) return fullType;
3003
- return _typeTable.nameType (type, fullType,
3004
- hoistType: hoistType, definite: definite);
3005
- }
3006
-
3007
- JS .Expression _emitAnnotatedFunctionType (
3008
- FunctionType type, List <Annotation > metadata,
3009
- {List <FormalParameter > parameters,
3010
- bool lowerTypedef: false ,
3011
- bool nameType: true ,
3012
- bool hoistType: true ,
3013
- bool definite: false }) {
3014
- var result = _emitFunctionType (type,
3015
- parameters: parameters,
3016
- lowerTypedef: lowerTypedef,
3017
- nameType: nameType,
3018
- hoistType: hoistType,
3019
- definite: definite);
3020
- return _emitAnnotatedResult (result, metadata);
3021
- }
3022
-
3023
- /// Emit the pieces of a function type, as an array of return type,
3024
- /// regular args, and optional/named args.
3025
- List <JS .Expression > _emitFunctionTypeParts (FunctionType type,
3026
- {List <FormalParameter > parameters,
3027
- bool lowerTypedef: false ,
3028
- bool nameType: true ,
3029
- bool hoistType: true }) {
3030
2995
var parameterTypes = type.normalParameterTypes;
3031
2996
var optionalTypes = type.optionalParameterTypes;
3032
2997
var namedTypes = type.namedParameterTypes;
@@ -3052,25 +3017,51 @@ class CodeGenerator extends Object
3052
3017
typeParts = [rt, ra];
3053
3018
}
3054
3019
3020
+ JS .Expression fullType;
3055
3021
var typeFormals = type.typeFormals;
3022
+ String helperCall;
3056
3023
if (typeFormals.isNotEmpty) {
3057
- // TODO(jmesserly): this is a suboptimal representation for universal
3058
- // function types (as callable functions). See discussion at
3059
- // https://github.com/dart-lang/sdk/issues/27333
3060
3024
var tf = _emitTypeFormals (typeFormals);
3061
- var names = _typeTable.discharge (typeFormals);
3062
- var parts = new JS .ArrayInitializer (typeParts);
3063
- if (names.isEmpty) {
3064
- typeParts = [
3065
- js.call ('(#) => #' , [tf, parts])
3066
- ];
3067
- } else {
3068
- typeParts = [
3069
- js.call ('(#) => {#; return #;}' , [tf, names, parts])
3070
- ];
3025
+
3026
+ addTypeFormalsAsParameters (List <JS .Expression > elements) {
3027
+ var names = _typeTable.discharge (typeFormals);
3028
+ var array = new JS .ArrayInitializer (elements);
3029
+ return names.isEmpty
3030
+ ? js.call ('(#) => #' , [tf, array])
3031
+ : js.call ('(#) => {#; return #;}' , [tf, names, array]);
3032
+ }
3033
+
3034
+ typeParts = [addTypeFormalsAsParameters (typeParts)];
3035
+
3036
+ helperCall = definite ? 'gFnType(#)' : 'gFnTypeFuzzy(#)' ;
3037
+ // If any explicit bounds were passed, emit them.
3038
+ if (typeFormals.any ((t) => t.bound != null )) {
3039
+ var bounds = typeFormals.map ((t) => _emitType (t.type.bound)).toList ();
3040
+ typeParts.add (addTypeFormalsAsParameters (bounds));
3071
3041
}
3042
+ } else {
3043
+ helperCall = definite ? 'fnType(#)' : 'fnTypeFuzzy(#)' ;
3072
3044
}
3073
- return typeParts;
3045
+ fullType = _callHelper (helperCall, [typeParts]);
3046
+ if (! nameType) return fullType;
3047
+ return _typeTable.nameType (type, fullType,
3048
+ hoistType: hoistType, definite: definite);
3049
+ }
3050
+
3051
+ JS .Expression _emitAnnotatedFunctionType (
3052
+ FunctionType type, List <Annotation > metadata,
3053
+ {List <FormalParameter > parameters,
3054
+ bool lowerTypedef: false ,
3055
+ bool nameType: true ,
3056
+ bool hoistType: true ,
3057
+ bool definite: false }) {
3058
+ var result = _emitFunctionType (type,
3059
+ parameters: parameters,
3060
+ lowerTypedef: lowerTypedef,
3061
+ nameType: nameType,
3062
+ hoistType: hoistType,
3063
+ definite: definite);
3064
+ return _emitAnnotatedResult (result, metadata);
3074
3065
}
3075
3066
3076
3067
/// Emits an expression that lets you access statics on a [type] from code.
0 commit comments