Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: sdk/lib/_internal/js_runtime/lib/js_rti.dart

Issue 2699073003: Support `void` as generic argument.
Patch Set: Add specialized messages for `void` for-ins. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/js_rti.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/js_rti.dart b/sdk/lib/_internal/js_runtime/lib/js_rti.dart
index 8ee404e4496207cb02cd657fac502177c8506476..8e4afabc762ab0425a6598d6099db6ae72b6e247 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_rti.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_rti.dart
@@ -162,6 +162,9 @@ String runtimeTypeToString(var rti, {String onTypeVariable(int i)}) {
if (rti == null) {
return 'dynamic';
}
+ if (isVoidType(rti)) {
+ return "void";
+ }
if (isJsArray(rti)) {
// A list representing a type with arguments.
return getRuntimeTypeAsString(rti, onTypeVariable: onTypeVariable);
@@ -191,15 +194,10 @@ String runtimeTypeToString(var rti, {String onTypeVariable(int i)}) {
String _functionRtiToString(var rti, String onTypeVariable(int i)) {
String returnTypeText;
- String voidTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_VOID_RETURN_TAG);
- if (JS('bool', '!!#[#]', rti, voidTag)) {
- returnTypeText = 'void';
- } else {
- String returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
- var returnRti = JS('', '#[#]', rti, returnTypeTag);
- returnTypeText =
- runtimeTypeToString(returnRti, onTypeVariable: onTypeVariable);
- }
+ String returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
+ var returnRti = JS('', '#[#]', rti, returnTypeTag);
+ returnTypeText =
+ runtimeTypeToString(returnRti, onTypeVariable: onTypeVariable);
String argumentsText = '';
String sep = '';
@@ -532,6 +530,9 @@ bool isSubtype(var s, var t) {
// If either type is dynamic, [s] is a subtype of [t].
if (s == null || t == null) return true;
if (isNullType(s)) return true;
+ if (isVoidType(t)) return true;
+ if (isVoidType(s)) return isDartObjectTypeRti(t);
+
if (isDartFunctionType(t)) {
return isFunctionSubtype(s, t);
}
@@ -626,17 +627,13 @@ bool areAssignableMaps(var s, var t) {
bool isFunctionSubtype(var s, var t) {
assert(isDartFunctionType(t));
if (!isDartFunctionType(s)) return false;
- var voidReturnTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_VOID_RETURN_TAG);
+
var returnTypeTag = JS_GET_NAME(JsGetName.FUNCTION_TYPE_RETURN_TYPE_TAG);
- if (hasField(s, voidReturnTag)) {
- if (hasNoField(t, voidReturnTag) && hasField(t, returnTypeTag)) {
- return false;
- }
- } else if (hasNoField(t, voidReturnTag)) {
- var sReturnType = getField(s, returnTypeTag);
- var tReturnType = getField(t, returnTypeTag);
- if (!isAssignable(sReturnType, tReturnType)) return false;
- }
+ var sReturnType = getField(s, returnTypeTag);
+ var tReturnType = getField(t, returnTypeTag);
+ if (!isAssignable(sReturnType, tReturnType)) return false;
+ if (isVoidType(sReturnType) && !isVoidType(tReturnType)) return false;
+
var requiredParametersTag =
JS_GET_NAME(JsGetName.FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG);
var sParameterTypes = getField(s, requiredParametersTag);

Powered by Google App Engine
This is Rietveld 408576698