[ddc] Delete typeRep() and legacyTypeRep()
Replaces all uses with the equivalent `TYPE_REF()` and `LEGACY_TYPE_REF()` because they are used in the shared dart:_rti library and there is no need to support both. Change-Id: I8c04eb12856cf6933a168f3e63351a45cd5d704e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344608 Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
committed by
Commit Queue
parent
1f35476e63
commit
1572bb563f
@@ -6577,10 +6577,6 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
||||
if (node.arguments.positional.isEmpty &&
|
||||
node.arguments.types.length == 1) {
|
||||
var type = node.arguments.types.single;
|
||||
if (name == 'typeRep') return _emitType(type);
|
||||
if (name == 'legacyTypeRep') {
|
||||
return _emitType(type.withDeclaredNullability(Nullability.legacy));
|
||||
}
|
||||
if (name == 'getGenericClassStatic') {
|
||||
if (type is InterfaceType) {
|
||||
return _emitTopLevelNameNoExternalInterop(type.classNode,
|
||||
|
||||
@@ -8,7 +8,7 @@ library dart.js;
|
||||
import 'dart:collection' show HashMap, ListMixin;
|
||||
|
||||
import 'dart:_js_helper' show NoReifyGeneric, Primitives;
|
||||
import 'dart:_foreign_helper' show JS;
|
||||
import 'dart:_foreign_helper' show JS, TYPE_REF;
|
||||
import 'dart:_interceptors' show LegacyJavaScriptObject;
|
||||
import 'dart:_internal' show patch;
|
||||
import 'dart:_runtime' as dart;
|
||||
@@ -371,8 +371,7 @@ Object? _convertToDart(Object? o) {
|
||||
int ms = JS('!', '#.getTime()', o);
|
||||
return DateTime.fromMillisecondsSinceEpoch(ms);
|
||||
} else if (o is _DartObject &&
|
||||
!identical(
|
||||
dart.getReifiedType(o), dart.typeRep<LegacyJavaScriptObject>())) {
|
||||
!identical(dart.getReifiedType(o), TYPE_REF<LegacyJavaScriptObject>())) {
|
||||
return o._dartObj;
|
||||
} else {
|
||||
return _wrapToDart(o);
|
||||
|
||||
@@ -215,7 +215,7 @@ generic(typeConstructor, setBaseClass) => JS('', '''(() => {
|
||||
if (args.length != length && args.length != 0) {
|
||||
$throwInternalError('requires ' + length + ' or 0 type arguments');
|
||||
}
|
||||
while (args.length < length) args.push(${typeRep<dynamic>()});
|
||||
while (args.length < length) args.push(${TYPE_REF<dynamic>()});
|
||||
|
||||
let value = resultMap;
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
@@ -164,7 +164,7 @@ getReifiedType(obj) {
|
||||
if (JS_GET_FLAG('NEW_RUNTIME_TYPES')) {
|
||||
switch (JS<String>('!', 'typeof #', obj)) {
|
||||
case "object":
|
||||
if (obj == null) return typeRep<Null>();
|
||||
if (obj == null) return TYPE_REF<Null>();
|
||||
if (_jsInstanceOf(obj, RecordImpl)) return getRtiForRecord(obj);
|
||||
if (_jsInstanceOf(obj, Object) ||
|
||||
JS('', '#[#]', obj, _extensionType) != null) {
|
||||
@@ -172,28 +172,28 @@ getReifiedType(obj) {
|
||||
return rti.instanceType(obj);
|
||||
}
|
||||
// Otherwise assume this is a JS interop object.
|
||||
return typeRep<LegacyJavaScriptObject>();
|
||||
return TYPE_REF<LegacyJavaScriptObject>();
|
||||
case "function":
|
||||
// Dart functions are tagged with a signature.
|
||||
var signature =
|
||||
JS('', '#[#]', obj, JS_GET_NAME(JsGetName.SIGNATURE_NAME));
|
||||
if (signature != null) return signature;
|
||||
return typeRep<JavaScriptFunction>();
|
||||
return TYPE_REF<JavaScriptFunction>();
|
||||
case "undefined":
|
||||
return typeRep<Null>();
|
||||
return TYPE_REF<Null>();
|
||||
case "number":
|
||||
return JS('', 'Math.floor(#) == # ? # : #', obj, obj, typeRep<int>(),
|
||||
typeRep<double>());
|
||||
return JS('', 'Math.floor(#) == # ? # : #', obj, obj, TYPE_REF<int>(),
|
||||
TYPE_REF<double>());
|
||||
case "boolean":
|
||||
return typeRep<bool>();
|
||||
return TYPE_REF<bool>();
|
||||
case "string":
|
||||
return typeRep<String>();
|
||||
return TYPE_REF<String>();
|
||||
case "symbol":
|
||||
return typeRep<JavaScriptSymbol>();
|
||||
return TYPE_REF<JavaScriptSymbol>();
|
||||
case "bigint":
|
||||
return typeRep<JavaScriptBigInt>();
|
||||
return TYPE_REF<JavaScriptBigInt>();
|
||||
default:
|
||||
return typeRep<LegacyJavaScriptObject>();
|
||||
return TYPE_REF<LegacyJavaScriptObject>();
|
||||
}
|
||||
} else {
|
||||
switch (JS<String>('!', 'typeof #', obj)) {
|
||||
@@ -206,13 +206,13 @@ getReifiedType(obj) {
|
||||
return JS('', '#.constructor', obj);
|
||||
}
|
||||
var result = JS('', '#[#]', obj, _extensionType);
|
||||
if (result == null) return typeRep<LegacyJavaScriptObject>();
|
||||
if (result == null) return TYPE_REF<LegacyJavaScriptObject>();
|
||||
return result;
|
||||
case "function":
|
||||
// All Dart functions and callable classes must set _runtimeType
|
||||
var result = JS('', '#[#]', obj, _runtimeType);
|
||||
if (result != null) return result;
|
||||
return typeRep<LegacyJavaScriptObject>();
|
||||
return TYPE_REF<LegacyJavaScriptObject>();
|
||||
case "undefined":
|
||||
return JS('', '#', Null);
|
||||
case "number":
|
||||
@@ -222,11 +222,11 @@ getReifiedType(obj) {
|
||||
case "string":
|
||||
return JS('', '#', String);
|
||||
case "symbol":
|
||||
return typeRep<JavaScriptSymbol>();
|
||||
return TYPE_REF<JavaScriptSymbol>();
|
||||
case "bigint":
|
||||
return typeRep<JavaScriptBigInt>();
|
||||
return TYPE_REF<JavaScriptBigInt>();
|
||||
default:
|
||||
return typeRep<LegacyJavaScriptObject>();
|
||||
return TYPE_REF<LegacyJavaScriptObject>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ import 'dart:_foreign_helper'
|
||||
JS_GET_FLAG,
|
||||
JS_GET_NAME,
|
||||
JSExportName,
|
||||
LEGACY_TYPE_REF,
|
||||
rest,
|
||||
TYPE_REF,
|
||||
spread;
|
||||
import 'dart:_interceptors'
|
||||
show
|
||||
|
||||
@@ -192,8 +192,8 @@ class DynamicType extends DartType {
|
||||
@notNull
|
||||
bool _isJsObject(obj) => JS_GET_FLAG("NEW_RUNTIME_TYPES")
|
||||
? obj is LegacyJavaScriptObject
|
||||
: JS(
|
||||
'!', '# === #', getReifiedType(obj), typeRep<LegacyJavaScriptObject>());
|
||||
: JS('!', '# === #', getReifiedType(obj),
|
||||
TYPE_REF<LegacyJavaScriptObject>());
|
||||
|
||||
/// Asserts that [f] is a native JS function and returns it if so.
|
||||
///
|
||||
@@ -1499,22 +1499,6 @@ external bool _jsInstanceOf(obj, cls);
|
||||
@notNull
|
||||
external bool _equalType(type, cls);
|
||||
|
||||
/// Extracts the type argument as an unwrapped type preserving all forms of
|
||||
/// nullability.
|
||||
///
|
||||
/// Acts as a way to bypass extra calls of [wrapType] and [unwrapType]. For
|
||||
/// example `typeRep<Object?>()` emits `dart.nullable(core.Object)` directly.
|
||||
@notNull
|
||||
external Type typeRep<T>();
|
||||
|
||||
/// Extracts the type argument as an unwrapped type and performs a shallow
|
||||
/// replacement of the nullability to a legacy type.
|
||||
///
|
||||
/// Acts as a way to bypass extra calls of [wrapType] and [unwrapType]. For
|
||||
/// example `legacyTypeRep<Object>()` emits `dart.legacy(core.Object)` directly.
|
||||
@notNull
|
||||
external Type legacyTypeRep<T>();
|
||||
|
||||
@notNull
|
||||
bool _isFutureOr(type) {
|
||||
var genericClass = getGenericClass(type);
|
||||
@@ -1546,14 +1530,14 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
|
||||
// "Left Top".
|
||||
if (_equalType(t1, dynamic) || JS<bool>('!', '# === #', t1, void_)) {
|
||||
return _isSubtype(typeRep<Object?>(), t2, strictMode);
|
||||
return _isSubtype(TYPE_REF<Object?>(), t2, strictMode);
|
||||
}
|
||||
|
||||
// "Right Object".
|
||||
if (_equalType(t2, Object)) {
|
||||
if (_isFutureOr(t1)) {
|
||||
var t1TypeArg = JS('', '#[0]', getGenericArgs(t1));
|
||||
return _isSubtype(t1TypeArg, typeRep<Object>(), strictMode);
|
||||
return _isSubtype(t1TypeArg, TYPE_REF<Object>(), strictMode);
|
||||
}
|
||||
|
||||
if (_jsInstanceOf(t1, LegacyType)) {
|
||||
@@ -1571,7 +1555,7 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
if (_equalType(t1, Null)) {
|
||||
if (_isFutureOr(t2)) {
|
||||
var t2TypeArg = JS('', '#[0]', getGenericArgs(t2));
|
||||
return _isSubtype(typeRep<Null>(), t2TypeArg, strictMode);
|
||||
return _isSubtype(TYPE_REF<Null>(), t2TypeArg, strictMode);
|
||||
}
|
||||
|
||||
return _equalType(t2, Null) ||
|
||||
@@ -1612,7 +1596,7 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
// "Left Nullable".
|
||||
if (_jsInstanceOf(t1, NullableType)) {
|
||||
return _isSubtype(JS<NullableType>('!', '#', t1).type, t2, strictMode) &&
|
||||
_isSubtype(typeRep<Null>(), t2, strictMode);
|
||||
_isSubtype(TYPE_REF<Null>(), t2, strictMode);
|
||||
}
|
||||
|
||||
if (_isFutureOr(t2)) {
|
||||
@@ -1627,7 +1611,7 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
// "Right Nullable".
|
||||
if (_jsInstanceOf(t2, NullableType)) {
|
||||
return _isSubtype(t1, JS<NullableType>('!', '#', t2).type, strictMode) ||
|
||||
_isSubtype(t1, typeRep<Null>(), strictMode);
|
||||
_isSubtype(t1, TYPE_REF<Null>(), strictMode);
|
||||
}
|
||||
|
||||
// Abstract Record.
|
||||
@@ -1665,7 +1649,7 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
// non-`@staticInterop` package:js types <: LegacyJavaScriptObject
|
||||
|
||||
if (_isInterfaceSubtype(
|
||||
t1, typeRep<LegacyJavaScriptObject>(), strictMode) &&
|
||||
t1, TYPE_REF<LegacyJavaScriptObject>(), strictMode) &&
|
||||
// TODO(srujzs): We don't have a mechanism to determine if *some*
|
||||
// PackageJSType implements t2. This will possibly require keeping a map
|
||||
// of these relationships for this subtyping check. For now, this will
|
||||
@@ -1676,7 +1660,7 @@ bool _isSubtype(t1, t2, @notNull bool strictMode) {
|
||||
|
||||
if (_isInterfaceSubtype(t1, _packageJSTypeForSubtyping, strictMode) &&
|
||||
_isInterfaceSubtype(
|
||||
typeRep<LegacyJavaScriptObject>(), t2, strictMode)) {
|
||||
TYPE_REF<LegacyJavaScriptObject>(), t2, strictMode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -326,11 +326,13 @@ external RAW_DART_FUNCTION_REF(Function function);
|
||||
/// Returns a reference to the internal value that represents [T].
|
||||
///
|
||||
/// Static calls to this function are inserted directly by the compiler.
|
||||
@notNull
|
||||
external Rti TYPE_REF<T>();
|
||||
|
||||
/// Returns a reference to the internal value that represents [T]*.
|
||||
///
|
||||
/// Static calls to this function are inserted directly by the compiler.
|
||||
@notNull
|
||||
external Rti LEGACY_TYPE_REF<T>();
|
||||
|
||||
/// JavaScript string concatenation. Inputs must be Strings.
|
||||
|
||||
@@ -7,8 +7,7 @@ library dart._interceptors;
|
||||
import 'dart:collection';
|
||||
import 'dart:_internal' hide Symbol;
|
||||
import 'dart:_js_helper';
|
||||
import 'dart:_foreign_helper'
|
||||
show JS, JS_EMBEDDED_GLOBAL, JS_GET_FLAG, JSExportName;
|
||||
import 'dart:_foreign_helper' show JS, JS_GET_FLAG, TYPE_REF;
|
||||
import 'dart:math' show Random, ln2;
|
||||
import 'dart:_rti' as rti show createRuntimeType, Rti;
|
||||
import 'dart:_runtime' as dart;
|
||||
|
||||
@@ -49,7 +49,7 @@ class JSArray<E> extends JavaScriptObject
|
||||
/// NOTE: The name of this getter is directly tied to the result of compiling
|
||||
/// `JS_EMBEDDED_GLOBAL('', ARRAY_RTI_PROPERTY)`.
|
||||
Object get arrayRti => JS_GET_FLAG('NEW_RUNTIME_TYPES')
|
||||
? dart.typeRep<JSArray<E>>()
|
||||
? TYPE_REF<JSArray<E>>()
|
||||
: throw dart.throwUnimplementedInCurrentRti();
|
||||
|
||||
/// Unsupported action, only provided here to help diagnosis of an accidental
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:_runtime' show gFnType, typeRep, isSubtypeOf;
|
||||
import 'dart:_foreign_helper' show TYPE_REF;
|
||||
import 'dart:_runtime' show gFnType, isSubtypeOf;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
@@ -10,7 +11,8 @@ import 'package:expect/expect.dart';
|
||||
/// the form: <T extends [bound]> void -> void.
|
||||
///
|
||||
// TODO(nshahan): The generic function type is created as a legacy type.
|
||||
genericFunction(bound) => gFnType((T) => [typeRep<void>(), []], (T) => [bound]);
|
||||
genericFunction(bound) =>
|
||||
gFnType((T) => [TYPE_REF<void>(), []], (T) => [bound]);
|
||||
|
||||
/// Returns an unwrapped generic function type with a bounded type argument in
|
||||
/// the form: <T extends [bound]> [argumentType] -> T.
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:_foreign_helper' show JS;
|
||||
import 'dart:_runtime' show gFnType, typeRep;
|
||||
import 'dart:_foreign_helper' show JS, TYPE_REF;
|
||||
import 'dart:_runtime' show gFnType;
|
||||
|
||||
/// Returns an unwrapped generic function type with a bounded type argument in
|
||||
/// the form: <T extends [bound]> void -> void.
|
||||
Object genericFunction(Object bound) =>
|
||||
gFnType((T) => [typeRep<void>(), []], (T) => [bound]);
|
||||
gFnType((T) => [TYPE_REF<void>(), []], (T) => [bound]);
|
||||
|
||||
/// Returns an unwrapped generic function type with a bounded type argument in
|
||||
/// the form: <T extends [bound]> [argumentType] -> T.
|
||||
|
||||
+109
-106
@@ -4,7 +4,7 @@
|
||||
|
||||
// Requirements=nnbd-strong
|
||||
|
||||
import 'dart:_runtime' show typeRep, legacyTypeRep;
|
||||
import 'dart:_foreign_helper' show LEGACY_TYPE_REF, TYPE_REF;
|
||||
import 'dart:async' show FutureOr;
|
||||
|
||||
import 'runtime_utils.dart'
|
||||
@@ -30,258 +30,261 @@ class F extends E<B, B> {}
|
||||
void main() {
|
||||
// Top type symmetry.
|
||||
// Object? <:> dynamic
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<dynamic>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<dynamic>());
|
||||
// Object? <:> void
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<void>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<void>());
|
||||
// void <:> dynamic
|
||||
checkMutualSubtype(typeRep<void>(), typeRep<dynamic>());
|
||||
checkMutualSubtype(TYPE_REF<void>(), TYPE_REF<dynamic>());
|
||||
|
||||
// Bottom is subtype of top.
|
||||
// Never <: dynamic
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<dynamic>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<dynamic>());
|
||||
// Never <: void
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<void>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<void>());
|
||||
// Never <: Object?
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object?>());
|
||||
|
||||
// Object is between top and bottom.
|
||||
// Object <: Object?
|
||||
checkSubtype(typeRep<Object>(), typeRep<Object?>());
|
||||
checkSubtype(TYPE_REF<Object>(), TYPE_REF<Object?>());
|
||||
// Never <: Object
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<Object>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object>());
|
||||
|
||||
// Null is between top and bottom.
|
||||
// Null <: Object?
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Object?>());
|
||||
// Never <: Null
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<Null>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Null>());
|
||||
|
||||
// Class is between Object and bottom.
|
||||
// A <: Object
|
||||
checkProperSubtype(typeRep<A>(), typeRep<dynamic>());
|
||||
checkProperSubtype(TYPE_REF<A>(), TYPE_REF<dynamic>());
|
||||
// Never <: A
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<A>());
|
||||
|
||||
// Nullable types are a union of T and Null.
|
||||
// A <: A?
|
||||
checkProperSubtype(typeRep<A>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<A>(), TYPE_REF<A?>());
|
||||
// Null <: A?
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<A?>());
|
||||
// A? <: Object?
|
||||
checkProperSubtype(typeRep<A?>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<A?>(), TYPE_REF<Object?>());
|
||||
|
||||
// Legacy types will eventually be migrated to T or T? but until then are
|
||||
// symmetric with both.
|
||||
// Object* <:> Object
|
||||
checkMutualSubtype(legacyTypeRep<Object>(), typeRep<Object>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<Object>(), TYPE_REF<Object>());
|
||||
// Object* <:> Object?
|
||||
checkMutualSubtype(legacyTypeRep<Object>(), typeRep<Object?>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<Object>(), TYPE_REF<Object?>());
|
||||
|
||||
// Bottom Types
|
||||
// Null <: Object*
|
||||
checkSubtype(typeRep<Null>(), legacyTypeRep<Object>());
|
||||
checkSubtype(TYPE_REF<Null>(), LEGACY_TYPE_REF<Object>());
|
||||
// Never <: Object*
|
||||
checkSubtype(typeRep<Never>(), legacyTypeRep<Object>());
|
||||
checkSubtype(TYPE_REF<Never>(), LEGACY_TYPE_REF<Object>());
|
||||
// A* <:> A
|
||||
checkMutualSubtype(legacyTypeRep<A>(), typeRep<A>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<A>());
|
||||
// A* <:> A?
|
||||
checkMutualSubtype(legacyTypeRep<A>(), typeRep<A?>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<A?>());
|
||||
// A* <: Object
|
||||
checkProperSubtype(legacyTypeRep<A>(), typeRep<Object>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<Object>());
|
||||
// A* <: Object?
|
||||
checkProperSubtype(legacyTypeRep<A>(), typeRep<Object?>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<Object?>());
|
||||
// Null <: A*
|
||||
checkProperSubtype(typeRep<Null>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), LEGACY_TYPE_REF<A>());
|
||||
// Never <: A*
|
||||
checkProperSubtype(typeRep<Never>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), LEGACY_TYPE_REF<A>());
|
||||
|
||||
// Futures.
|
||||
// Null <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Object>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object? <:> FutureOr<Object?>
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<FutureOr<Object?>>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object <:> FutureOr<Object>
|
||||
checkMutualSubtype(typeRep<Object>(), typeRep<FutureOr<Object>>());
|
||||
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object>>());
|
||||
// Object <: FutureOr<dynamic>
|
||||
checkProperSubtype(typeRep<Object>(), typeRep<FutureOr<dynamic>>());
|
||||
checkProperSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<dynamic>>());
|
||||
// Object <: FutureOr<void>
|
||||
checkProperSubtype(typeRep<Object>(), typeRep<FutureOr<void>>());
|
||||
checkProperSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<void>>());
|
||||
// Future<Object> <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Future<Object>>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(TYPE_REF<Future<Object>>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Future<Object?> <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Future<Object?>>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(
|
||||
TYPE_REF<Future<Object?>>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// FutureOr<Never> <: Future<Never>
|
||||
checkSubtype(typeRep<FutureOr<Never>>(), typeRep<Future<Never>>());
|
||||
checkSubtype(TYPE_REF<FutureOr<Never>>(), TYPE_REF<Future<Never>>());
|
||||
// Future<B> <: FutureOr<A>
|
||||
checkProperSubtype(typeRep<Future<B>>(), typeRep<FutureOr<A>>());
|
||||
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<FutureOr<A>>());
|
||||
// B <: <: FutureOr<A>
|
||||
checkProperSubtype(typeRep<B>(), typeRep<FutureOr<A>>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<FutureOr<A>>());
|
||||
// Future<B> <: Future<A>
|
||||
checkProperSubtype(typeRep<Future<B>>(), typeRep<Future<A>>());
|
||||
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<Future<A>>());
|
||||
|
||||
// Interface subtypes.
|
||||
// A <: A
|
||||
checkSubtype(typeRep<A>(), typeRep<A>());
|
||||
checkSubtype(TYPE_REF<A>(), TYPE_REF<A>());
|
||||
// B <: A
|
||||
checkProperSubtype(typeRep<B>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A>());
|
||||
// C <: B
|
||||
checkProperSubtype(typeRep<C>(), typeRep<B>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<B>());
|
||||
// C <: A
|
||||
checkProperSubtype(typeRep<C>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A>());
|
||||
|
||||
// Functions.
|
||||
// A -> B <: Function
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<Function>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<Function>());
|
||||
|
||||
// A -> B <: A -> B
|
||||
checkSubtype(typeRep<B Function(A)>(), typeRep<B Function(A)>());
|
||||
checkSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(A)>());
|
||||
|
||||
// A -> B <: B -> B
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<B Function(B)>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(B)>());
|
||||
|
||||
// A -> B <: A -> A
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<A Function(A)>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<A Function(A)>());
|
||||
|
||||
// Generic Function Subtypes.
|
||||
// Bound is a built in type.
|
||||
// <T extends int> void -> void <: <T extends int> void -> void
|
||||
checkSubtype(
|
||||
genericFunction(typeRep<int>()), genericFunction(typeRep<int>()));
|
||||
genericFunction(TYPE_REF<int>()), genericFunction(TYPE_REF<int>()));
|
||||
|
||||
// <T extends String> A -> T <: <T extends String> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<String>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<String>(), typeRep<B>()));
|
||||
checkProperSubtype(functionGenericReturn(TYPE_REF<String>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<String>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends double> T -> B <: <T extends double> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<double>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<double>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<double>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<double>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a function type.
|
||||
// <T extends A -> B> void -> void <: <T extends A -> B> void -> void
|
||||
checkSubtype(genericFunction(typeRep<A Function(B)>()),
|
||||
genericFunction(typeRep<A Function(B)>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<A Function(B)>()),
|
||||
genericFunction(TYPE_REF<A Function(B)>()));
|
||||
|
||||
// <T extends A -> B> A -> T <: <T extends A -> B> B -> T
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(typeRep<A Function(B)>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<A Function(B)>(), typeRep<B>()));
|
||||
functionGenericReturn(TYPE_REF<A Function(B)>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<A Function(B)>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends A -> B> T -> B <: <T extends A -> B> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<A Function(B)>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<A Function(B)>(), typeRep<A>()));
|
||||
checkProperSubtype(
|
||||
functionGenericArg(TYPE_REF<A Function(B)>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<A Function(B)>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a user defined class.
|
||||
// <T extends B> void -> void <: <T extends B> void -> void
|
||||
checkSubtype(genericFunction(typeRep<B>()), genericFunction(typeRep<B>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<B>()), genericFunction(TYPE_REF<B>()));
|
||||
|
||||
// <T extends B> A -> T <: <T extends B> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<B>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<B>(), typeRep<B>()));
|
||||
checkProperSubtype(functionGenericReturn(TYPE_REF<B>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<B>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends B> T -> B <: <T extends B> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<B>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<B>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<B>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<B>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a Future.
|
||||
// <T extends Future<B>> void -> void <: <T extends Future<B>> void -> void
|
||||
checkSubtype(genericFunction(typeRep<Future<B>>()),
|
||||
genericFunction(typeRep<Future<B>>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<Future<B>>()),
|
||||
genericFunction(TYPE_REF<Future<B>>()));
|
||||
|
||||
// <T extends Future<B>> A -> T <: <T extends Future<B>> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<Future<B>>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<Future<B>>(), typeRep<B>()));
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(TYPE_REF<Future<B>>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<Future<B>>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends Future<B>> T -> B <: <T extends Future<B>> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<Future<B>>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<Future<B>>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<Future<B>>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<Future<B>>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a FutureOr.
|
||||
// <T extends FutureOr<B>> void -> void <:
|
||||
// <T extends FutureOr<B>> void -> void
|
||||
checkSubtype(genericFunction(typeRep<FutureOr<B>>()),
|
||||
genericFunction(typeRep<FutureOr<B>>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<FutureOr<B>>()),
|
||||
genericFunction(TYPE_REF<FutureOr<B>>()));
|
||||
|
||||
// <T extends FutureOr<B>> A -> T <: <T extends FutureOr<B>> B -> T
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(typeRep<FutureOr<B>>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<FutureOr<B>>(), typeRep<B>()));
|
||||
functionGenericReturn(TYPE_REF<FutureOr<B>>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<FutureOr<B>>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends FutureOr<B>> T -> B <: <T extends FutureOr<B>> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<FutureOr<B>>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<FutureOr<B>>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<FutureOr<B>>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<FutureOr<B>>(), TYPE_REF<A>()));
|
||||
|
||||
// Generics.
|
||||
// D <:> D<B>
|
||||
checkMutualSubtype(typeRep<D>(), typeRep<D<B>>());
|
||||
checkMutualSubtype(TYPE_REF<D>(), TYPE_REF<D<B>>());
|
||||
// D<C> <: D<B>
|
||||
checkProperSubtype(typeRep<D<C>>(), typeRep<D<B>>());
|
||||
checkProperSubtype(TYPE_REF<D<C>>(), TYPE_REF<D<B>>());
|
||||
|
||||
// F <: E
|
||||
checkProperSubtype(typeRep<F>(), typeRep<E>());
|
||||
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E>());
|
||||
// F <: E<A, A>
|
||||
checkProperSubtype(typeRep<F>(), typeRep<E<A, A>>());
|
||||
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E<A, A>>());
|
||||
// E<B, B> <: E
|
||||
checkProperSubtype(typeRep<E<B, B>>(), typeRep<E>());
|
||||
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E>());
|
||||
// E<B, B> <: E<A, A>
|
||||
checkProperSubtype(typeRep<E<B, B>>(), typeRep<E<A, A>>());
|
||||
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E<A, A>>());
|
||||
|
||||
// Nullable interface subtypes.
|
||||
// B <: A?
|
||||
checkProperSubtype(typeRep<B>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A?>());
|
||||
// C <: A?
|
||||
checkProperSubtype(typeRep<C>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A?>());
|
||||
// B? <: A?
|
||||
checkProperSubtype(typeRep<B?>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<B?>(), TYPE_REF<A?>());
|
||||
// C? <: A?
|
||||
checkProperSubtype(typeRep<C?>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<C?>(), TYPE_REF<A?>());
|
||||
|
||||
// Mixed mode.
|
||||
// B* <: A
|
||||
checkProperSubtype(legacyTypeRep<B>(), typeRep<A>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<B>(), TYPE_REF<A>());
|
||||
// B* <: A?
|
||||
checkProperSubtype(legacyTypeRep<B>(), typeRep<A?>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<B>(), TYPE_REF<A?>());
|
||||
// A* <\: B
|
||||
checkSubtypeFailure(legacyTypeRep<A>(), typeRep<B>());
|
||||
checkSubtypeFailure(LEGACY_TYPE_REF<A>(), TYPE_REF<B>());
|
||||
// B? <: A*
|
||||
checkProperSubtype(typeRep<B?>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B?>(), LEGACY_TYPE_REF<A>());
|
||||
// B <: A*
|
||||
checkProperSubtype(typeRep<B>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B>(), LEGACY_TYPE_REF<A>());
|
||||
// A <: B*
|
||||
checkSubtypeFailure(typeRep<A>(), legacyTypeRep<B>());
|
||||
checkSubtypeFailure(TYPE_REF<A>(), LEGACY_TYPE_REF<B>());
|
||||
// A? <: B*
|
||||
checkSubtypeFailure(typeRep<A?>(), legacyTypeRep<B>());
|
||||
checkSubtypeFailure(TYPE_REF<A?>(), LEGACY_TYPE_REF<B>());
|
||||
|
||||
// Allowed in weak mode.
|
||||
// dynamic <\: Object
|
||||
checkSubtypeFailure(typeRep<dynamic>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<dynamic>(), TYPE_REF<Object>());
|
||||
// void <\: Object
|
||||
checkSubtypeFailure(typeRep<void>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<void>(), TYPE_REF<Object>());
|
||||
// Object? <\: Object
|
||||
checkSubtypeFailure(typeRep<Object?>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<Object?>(), TYPE_REF<Object>());
|
||||
// A? <\: Object
|
||||
checkSubtypeFailure(typeRep<A?>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<A?>(), TYPE_REF<Object>());
|
||||
// A? <\: A
|
||||
checkSubtypeFailure(typeRep<A?>(), typeRep<A>());
|
||||
checkSubtypeFailure(TYPE_REF<A?>(), TYPE_REF<A>());
|
||||
// Null <\: Never
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<Never>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<Never>());
|
||||
// Null <\: Object
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<Object>());
|
||||
// Null <\: A
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<A>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<A>());
|
||||
// Null <\: FutureOr<A>
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<FutureOr<A>>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<FutureOr<A>>());
|
||||
// Null <\: Future<A>
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<Future<A>>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<Future<A>>());
|
||||
// FutureOr<Null> <\: Future<Null>
|
||||
checkSubtypeFailure(typeRep<FutureOr<Null>>(), typeRep<Future<Null>>());
|
||||
checkSubtypeFailure(TYPE_REF<FutureOr<Null>>(), TYPE_REF<Future<Null>>());
|
||||
// Null <\: Future<A?>
|
||||
checkSubtypeFailure(typeRep<Null>(), typeRep<Future<A?>>());
|
||||
checkSubtypeFailure(TYPE_REF<Null>(), TYPE_REF<Future<A?>>());
|
||||
// FutureOr<Object?> <\: Object
|
||||
checkSubtypeFailure(typeRep<FutureOr<Object?>>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<FutureOr<Object?>>(), TYPE_REF<Object>());
|
||||
// FutureOr<dynamic> <\: Object
|
||||
checkSubtypeFailure(typeRep<FutureOr<dynamic>>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<FutureOr<dynamic>>(), TYPE_REF<Object>());
|
||||
// FutureOr<void> <\: Object
|
||||
checkSubtypeFailure(typeRep<FutureOr<void>>(), typeRep<Object>());
|
||||
checkSubtypeFailure(TYPE_REF<FutureOr<void>>(), TYPE_REF<Object>());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// Requirements=nnbd-weak
|
||||
|
||||
import 'dart:_runtime' show typeRep, legacyTypeRep;
|
||||
import 'dart:_foreign_helper' show LEGACY_TYPE_REF, TYPE_REF;
|
||||
import 'dart:async';
|
||||
|
||||
import 'runtime_utils.dart'
|
||||
@@ -30,258 +30,261 @@ class F extends E<B, B> {}
|
||||
void main() {
|
||||
// Top type symmetry.
|
||||
// Object? <:> dynamic
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<dynamic>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<dynamic>());
|
||||
// Object? <:> void
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<void>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<void>());
|
||||
// void <:> dynamic
|
||||
checkMutualSubtype(typeRep<void>(), typeRep<dynamic>());
|
||||
checkMutualSubtype(TYPE_REF<void>(), TYPE_REF<dynamic>());
|
||||
|
||||
// Bottom is subtype of top.
|
||||
// Never <: dynamic
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<dynamic>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<dynamic>());
|
||||
// Never <: void
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<void>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<void>());
|
||||
// Never <: Object?
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object?>());
|
||||
|
||||
// Object is between top and bottom.
|
||||
// Object <: Object?
|
||||
checkSubtype(typeRep<Object>(), typeRep<Object?>());
|
||||
checkSubtype(TYPE_REF<Object>(), TYPE_REF<Object?>());
|
||||
// Never <: Object
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<Object>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<Object>());
|
||||
|
||||
// Null is between top and bottom.
|
||||
// Null <: Object?
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Object?>());
|
||||
// Never <: Null
|
||||
checkSubtype(typeRep<Never>(), typeRep<Null>());
|
||||
checkSubtype(TYPE_REF<Never>(), TYPE_REF<Null>());
|
||||
|
||||
// Class is between Object and bottom.
|
||||
// A <: Object
|
||||
checkProperSubtype(typeRep<A>(), typeRep<dynamic>());
|
||||
checkProperSubtype(TYPE_REF<A>(), TYPE_REF<dynamic>());
|
||||
// Never <: A
|
||||
checkProperSubtype(typeRep<Never>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), TYPE_REF<A>());
|
||||
|
||||
// Nullable types are a union of T and Null.
|
||||
// A <: A?
|
||||
checkSubtype(typeRep<A>(), typeRep<A?>());
|
||||
checkSubtype(TYPE_REF<A>(), TYPE_REF<A?>());
|
||||
// Null <: A?
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<A?>());
|
||||
// A? <: Object?
|
||||
checkProperSubtype(typeRep<A?>(), typeRep<Object?>());
|
||||
checkProperSubtype(TYPE_REF<A?>(), TYPE_REF<Object?>());
|
||||
|
||||
// Legacy types will eventually be migrated to T or T? but until then are
|
||||
// symmetric with both.
|
||||
// Object* <:> Object
|
||||
checkMutualSubtype(legacyTypeRep<Object>(), typeRep<Object>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<Object>(), TYPE_REF<Object>());
|
||||
// Object* <:> Object?
|
||||
checkMutualSubtype(legacyTypeRep<Object>(), typeRep<Object?>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<Object>(), TYPE_REF<Object?>());
|
||||
|
||||
// Bottom Types
|
||||
// Null <: Object*
|
||||
checkSubtype(typeRep<Null>(), legacyTypeRep<Object>());
|
||||
checkSubtype(TYPE_REF<Null>(), LEGACY_TYPE_REF<Object>());
|
||||
// Never <: Object*
|
||||
checkSubtype(typeRep<Never>(), legacyTypeRep<Object>());
|
||||
checkSubtype(TYPE_REF<Never>(), LEGACY_TYPE_REF<Object>());
|
||||
// A* <:> A
|
||||
checkMutualSubtype(legacyTypeRep<A>(), typeRep<A>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<A>());
|
||||
// A* <:> A?
|
||||
checkMutualSubtype(legacyTypeRep<A>(), typeRep<A?>());
|
||||
checkMutualSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<A?>());
|
||||
// A* <: Object
|
||||
checkProperSubtype(legacyTypeRep<A>(), typeRep<Object>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<Object>());
|
||||
// A* <: Object?
|
||||
checkProperSubtype(legacyTypeRep<A>(), typeRep<Object?>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<A>(), TYPE_REF<Object?>());
|
||||
// Null <: A*
|
||||
checkProperSubtype(typeRep<Null>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), LEGACY_TYPE_REF<A>());
|
||||
// Never <: A*
|
||||
checkProperSubtype(typeRep<Never>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Never>(), LEGACY_TYPE_REF<A>());
|
||||
|
||||
// Futures.
|
||||
// Null <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object <: FutureOr<Object?>
|
||||
checkSubtype(typeRep<Object>(), typeRep<FutureOr<Object?>>());
|
||||
checkSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object? <:> FutureOr<Object?>
|
||||
checkMutualSubtype(typeRep<Object?>(), typeRep<FutureOr<Object?>>());
|
||||
checkMutualSubtype(TYPE_REF<Object?>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Object <:> FutureOr<Object>
|
||||
checkMutualSubtype(typeRep<Object>(), typeRep<FutureOr<Object>>());
|
||||
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<Object>>());
|
||||
// Object <:> FutureOr<dynamic>
|
||||
checkMutualSubtype(typeRep<Object>(), typeRep<FutureOr<dynamic>>());
|
||||
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<dynamic>>());
|
||||
// Object <:> FutureOr<void>
|
||||
checkMutualSubtype(typeRep<Object>(), typeRep<FutureOr<void>>());
|
||||
checkMutualSubtype(TYPE_REF<Object>(), TYPE_REF<FutureOr<void>>());
|
||||
// Future<Object> <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Future<Object>>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(TYPE_REF<Future<Object>>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// Future<Object?> <: FutureOr<Object?>
|
||||
checkProperSubtype(typeRep<Future<Object?>>(), typeRep<FutureOr<Object?>>());
|
||||
checkProperSubtype(
|
||||
TYPE_REF<Future<Object?>>(), TYPE_REF<FutureOr<Object?>>());
|
||||
// FutureOr<Never> <: Future<Never>
|
||||
checkSubtype(typeRep<FutureOr<Never>>(), typeRep<Future<Never>>());
|
||||
checkSubtype(TYPE_REF<FutureOr<Never>>(), TYPE_REF<Future<Never>>());
|
||||
// Future<B> <: FutureOr<A>
|
||||
checkProperSubtype(typeRep<Future<B>>(), typeRep<FutureOr<A>>());
|
||||
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<FutureOr<A>>());
|
||||
// B <: <: FutureOr<A>
|
||||
checkProperSubtype(typeRep<B>(), typeRep<FutureOr<A>>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<FutureOr<A>>());
|
||||
// Future<B> <: Future<A>
|
||||
checkProperSubtype(typeRep<Future<B>>(), typeRep<Future<A>>());
|
||||
checkProperSubtype(TYPE_REF<Future<B>>(), TYPE_REF<Future<A>>());
|
||||
|
||||
// Interface subtypes.
|
||||
// A <: A
|
||||
checkSubtype(typeRep<A>(), typeRep<A>());
|
||||
checkSubtype(TYPE_REF<A>(), TYPE_REF<A>());
|
||||
// B <: A
|
||||
checkProperSubtype(typeRep<B>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A>());
|
||||
// C <: B
|
||||
checkProperSubtype(typeRep<C>(), typeRep<B>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<B>());
|
||||
// C <: A
|
||||
checkProperSubtype(typeRep<C>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A>());
|
||||
|
||||
// Functions.
|
||||
// A -> B <: Function
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<Function>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<Function>());
|
||||
|
||||
// A -> B <: A -> B
|
||||
checkSubtype(typeRep<B Function(A)>(), typeRep<B Function(A)>());
|
||||
checkSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(A)>());
|
||||
|
||||
// A -> B <: B -> B
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<B Function(B)>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<B Function(B)>());
|
||||
|
||||
// A -> B <: A -> A
|
||||
checkProperSubtype(typeRep<B Function(A)>(), typeRep<A Function(A)>());
|
||||
checkProperSubtype(TYPE_REF<B Function(A)>(), TYPE_REF<A Function(A)>());
|
||||
|
||||
// Generic Function Subtypes.
|
||||
// Bound is a built in type.
|
||||
// <T extends int> void -> void <: <T extends int> void -> void
|
||||
checkSubtype(
|
||||
genericFunction(typeRep<int>()), genericFunction(typeRep<int>()));
|
||||
genericFunction(TYPE_REF<int>()), genericFunction(TYPE_REF<int>()));
|
||||
|
||||
// <T extends String> A -> T <: <T extends String> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<String>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<String>(), typeRep<B>()));
|
||||
checkProperSubtype(functionGenericReturn(TYPE_REF<String>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<String>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends double> T -> B <: <T extends double> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<double>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<double>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<double>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<double>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a function type.
|
||||
// <T extends A -> B> void -> void <: <T extends A -> B> void -> void
|
||||
checkSubtype(genericFunction(typeRep<A Function(B)>()),
|
||||
genericFunction(typeRep<A Function(B)>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<A Function(B)>()),
|
||||
genericFunction(TYPE_REF<A Function(B)>()));
|
||||
|
||||
// <T extends A -> B> A -> T <: <T extends A -> B> B -> T
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(typeRep<A Function(B)>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<A Function(B)>(), typeRep<B>()));
|
||||
functionGenericReturn(TYPE_REF<A Function(B)>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<A Function(B)>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends A -> B> T -> B <: <T extends A -> B> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<A Function(B)>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<A Function(B)>(), typeRep<A>()));
|
||||
checkProperSubtype(
|
||||
functionGenericArg(TYPE_REF<A Function(B)>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<A Function(B)>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a user defined class.
|
||||
// <T extends B> void -> void <: <T extends B> void -> void
|
||||
checkSubtype(genericFunction(typeRep<B>()), genericFunction(typeRep<B>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<B>()), genericFunction(TYPE_REF<B>()));
|
||||
|
||||
// <T extends B> A -> T <: <T extends B> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<B>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<B>(), typeRep<B>()));
|
||||
checkProperSubtype(functionGenericReturn(TYPE_REF<B>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<B>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends B> T -> B <: <T extends B> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<B>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<B>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<B>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<B>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a Future.
|
||||
// <T extends Future<B>> void -> void <: <T extends Future<B>> void -> void
|
||||
checkSubtype(genericFunction(typeRep<Future<B>>()),
|
||||
genericFunction(typeRep<Future<B>>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<Future<B>>()),
|
||||
genericFunction(TYPE_REF<Future<B>>()));
|
||||
|
||||
// <T extends Future<B>> A -> T <: <T extends Future<B>> B -> T
|
||||
checkProperSubtype(functionGenericReturn(typeRep<Future<B>>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<Future<B>>(), typeRep<B>()));
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(TYPE_REF<Future<B>>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<Future<B>>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends Future<B>> T -> B <: <T extends Future<B>> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<Future<B>>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<Future<B>>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<Future<B>>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<Future<B>>(), TYPE_REF<A>()));
|
||||
|
||||
// Bound is a FutureOr.
|
||||
// <T extends FutureOr<B>> void -> void <:
|
||||
// <T extends FutureOr<B>> void -> void
|
||||
checkSubtype(genericFunction(typeRep<FutureOr<B>>()),
|
||||
genericFunction(typeRep<FutureOr<B>>()));
|
||||
checkSubtype(genericFunction(TYPE_REF<FutureOr<B>>()),
|
||||
genericFunction(TYPE_REF<FutureOr<B>>()));
|
||||
|
||||
// <T extends FutureOr<B>> A -> T <: <T extends FutureOr<B>> B -> T
|
||||
checkProperSubtype(
|
||||
functionGenericReturn(typeRep<FutureOr<B>>(), typeRep<A>()),
|
||||
functionGenericReturn(typeRep<FutureOr<B>>(), typeRep<B>()));
|
||||
functionGenericReturn(TYPE_REF<FutureOr<B>>(), TYPE_REF<A>()),
|
||||
functionGenericReturn(TYPE_REF<FutureOr<B>>(), TYPE_REF<B>()));
|
||||
|
||||
// <T extends FutureOr<B>> T -> B <: <T extends FutureOr<B>> T -> A
|
||||
checkProperSubtype(functionGenericArg(typeRep<FutureOr<B>>(), typeRep<B>()),
|
||||
functionGenericArg(typeRep<FutureOr<B>>(), typeRep<A>()));
|
||||
checkProperSubtype(functionGenericArg(TYPE_REF<FutureOr<B>>(), TYPE_REF<B>()),
|
||||
functionGenericArg(TYPE_REF<FutureOr<B>>(), TYPE_REF<A>()));
|
||||
|
||||
// Generics.
|
||||
// D <:> D<B>
|
||||
checkMutualSubtype(typeRep<D>(), typeRep<D<B>>());
|
||||
checkMutualSubtype(TYPE_REF<D>(), TYPE_REF<D<B>>());
|
||||
// D<C> <: D<B>
|
||||
checkProperSubtype(typeRep<D<C>>(), typeRep<D<B>>());
|
||||
checkProperSubtype(TYPE_REF<D<C>>(), TYPE_REF<D<B>>());
|
||||
|
||||
// F <: E
|
||||
checkProperSubtype(typeRep<F>(), typeRep<E>());
|
||||
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E>());
|
||||
// F <: E<A, A>
|
||||
checkProperSubtype(typeRep<F>(), typeRep<E<A, A>>());
|
||||
checkProperSubtype(TYPE_REF<F>(), TYPE_REF<E<A, A>>());
|
||||
// E<B, B> <: E
|
||||
checkProperSubtype(typeRep<E<B, B>>(), typeRep<E>());
|
||||
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E>());
|
||||
// E<B, B> <: E<A, A>
|
||||
checkProperSubtype(typeRep<E<B, B>>(), typeRep<E<A, A>>());
|
||||
checkProperSubtype(TYPE_REF<E<B, B>>(), TYPE_REF<E<A, A>>());
|
||||
|
||||
// Nullable interface subtypes.
|
||||
// B <: A?
|
||||
checkProperSubtype(typeRep<B>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<B>(), TYPE_REF<A?>());
|
||||
// C <: A?
|
||||
checkProperSubtype(typeRep<C>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<C>(), TYPE_REF<A?>());
|
||||
// B? <: A?
|
||||
checkProperSubtype(typeRep<B?>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<B?>(), TYPE_REF<A?>());
|
||||
// C? <: A?
|
||||
checkProperSubtype(typeRep<C?>(), typeRep<A?>());
|
||||
checkProperSubtype(TYPE_REF<C?>(), TYPE_REF<A?>());
|
||||
|
||||
// Mixed mode.
|
||||
// B* <: A
|
||||
checkProperSubtype(legacyTypeRep<B>(), typeRep<A>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<B>(), TYPE_REF<A>());
|
||||
// B* <: A?
|
||||
checkProperSubtype(legacyTypeRep<B>(), typeRep<A?>());
|
||||
checkProperSubtype(LEGACY_TYPE_REF<B>(), TYPE_REF<A?>());
|
||||
// A* <\: B
|
||||
checkSubtypeFailure(legacyTypeRep<A>(), typeRep<B>());
|
||||
checkSubtypeFailure(LEGACY_TYPE_REF<A>(), TYPE_REF<B>());
|
||||
// B? <: A*
|
||||
checkProperSubtype(typeRep<B?>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B?>(), LEGACY_TYPE_REF<A>());
|
||||
// B <: A*
|
||||
checkProperSubtype(typeRep<B>(), legacyTypeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<B>(), LEGACY_TYPE_REF<A>());
|
||||
// A <: B*
|
||||
checkSubtypeFailure(typeRep<A>(), legacyTypeRep<B>());
|
||||
checkSubtypeFailure(TYPE_REF<A>(), LEGACY_TYPE_REF<B>());
|
||||
// A? <: B*
|
||||
checkSubtypeFailure(typeRep<A?>(), legacyTypeRep<B>());
|
||||
checkSubtypeFailure(TYPE_REF<A?>(), LEGACY_TYPE_REF<B>());
|
||||
|
||||
// Allowed in weak mode.
|
||||
// dynamic <: Object
|
||||
checkSubtype(typeRep<dynamic>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<dynamic>(), TYPE_REF<Object>());
|
||||
// void <: Object
|
||||
checkSubtype(typeRep<void>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<void>(), TYPE_REF<Object>());
|
||||
// Object? <: Object
|
||||
checkSubtype(typeRep<Object?>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<Object?>(), TYPE_REF<Object>());
|
||||
// A? <: Object
|
||||
checkProperSubtype(typeRep<A?>(), typeRep<Object>());
|
||||
checkProperSubtype(TYPE_REF<A?>(), TYPE_REF<Object>());
|
||||
// A? <: A
|
||||
checkSubtype(typeRep<A?>(), typeRep<A>());
|
||||
checkSubtype(TYPE_REF<A?>(), TYPE_REF<A>());
|
||||
// Null <: Never
|
||||
checkSubtype(typeRep<Null>(), typeRep<Never>());
|
||||
checkSubtype(TYPE_REF<Null>(), TYPE_REF<Never>());
|
||||
// Null <: Object
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<Object>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Object>());
|
||||
// Null <: A
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<A>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<A>());
|
||||
// Null <: FutureOr<A>
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<FutureOr<A>>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<FutureOr<A>>());
|
||||
// Null <: Future<A>
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<Future<A>>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Future<A>>());
|
||||
// FutureOr<Null> <: Future<Null>
|
||||
checkSubtype(typeRep<FutureOr<Null>>(), typeRep<Future<Null>>());
|
||||
checkSubtype(TYPE_REF<FutureOr<Null>>(), TYPE_REF<Future<Null>>());
|
||||
// Null <: Future<A?>
|
||||
checkProperSubtype(typeRep<Null>(), typeRep<Future<A?>>());
|
||||
checkProperSubtype(TYPE_REF<Null>(), TYPE_REF<Future<A?>>());
|
||||
// FutureOr<Object?> <: Object
|
||||
checkSubtype(typeRep<FutureOr<Object?>>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<FutureOr<Object?>>(), TYPE_REF<Object>());
|
||||
// FutureOr<dynamic> <: Object
|
||||
checkSubtype(typeRep<FutureOr<dynamic>>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<FutureOr<dynamic>>(), TYPE_REF<Object>());
|
||||
// FutureOr<void> <: Object
|
||||
checkSubtype(typeRep<FutureOr<void>>(), typeRep<Object>());
|
||||
checkSubtype(TYPE_REF<FutureOr<void>>(), TYPE_REF<Object>());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
// Requirements=nnbd
|
||||
|
||||
import 'dart:_runtime' show legacy, nullable, typeRep, legacyTypeRep;
|
||||
import 'dart:_foreign_helper' show LEGACY_TYPE_REF, TYPE_REF;
|
||||
import 'dart:_runtime' show legacy, nullable;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
@@ -12,26 +13,26 @@ class A {}
|
||||
|
||||
void main() {
|
||||
// A?? == A?
|
||||
Expect.identical(nullable(typeRep<A?>()), typeRep<A?>());
|
||||
Expect.identical(nullable(TYPE_REF<A?>()), TYPE_REF<A?>());
|
||||
// A?* == A?
|
||||
Expect.identical(legacy(typeRep<A?>()), typeRep<A?>());
|
||||
Expect.identical(legacy(TYPE_REF<A?>()), TYPE_REF<A?>());
|
||||
// A*? == A?
|
||||
Expect.identical(nullable(legacyTypeRep<A>()), typeRep<A?>());
|
||||
Expect.identical(nullable(LEGACY_TYPE_REF<A>()), TYPE_REF<A?>());
|
||||
// A** == A*
|
||||
Expect.identical(legacy(legacyTypeRep<A>()), legacyTypeRep<A>());
|
||||
Expect.identical(legacy(LEGACY_TYPE_REF<A>()), LEGACY_TYPE_REF<A>());
|
||||
|
||||
// The tests below need explicit wrapping in nullable and legacy to ensure
|
||||
// they appear at runtime and the runtime library normalizes them correctly.
|
||||
// Null? == Null
|
||||
Expect.identical(nullable(typeRep<Null>()), typeRep<Null>());
|
||||
Expect.identical(nullable(TYPE_REF<Null>()), TYPE_REF<Null>());
|
||||
// Never? == Null
|
||||
Expect.identical(nullable(typeRep<Never>()), typeRep<Null>());
|
||||
Expect.identical(nullable(TYPE_REF<Never>()), TYPE_REF<Null>());
|
||||
// dynamic? == dynamic
|
||||
Expect.identical(nullable(typeRep<dynamic>()), typeRep<dynamic>());
|
||||
Expect.identical(nullable(TYPE_REF<dynamic>()), TYPE_REF<dynamic>());
|
||||
// void? == void
|
||||
Expect.identical(nullable(typeRep<void>()), typeRep<void>());
|
||||
Expect.identical(nullable(TYPE_REF<void>()), TYPE_REF<void>());
|
||||
// dynamic* == dynamic
|
||||
Expect.identical(legacy(typeRep<dynamic>()), typeRep<dynamic>());
|
||||
Expect.identical(legacy(TYPE_REF<dynamic>()), TYPE_REF<dynamic>());
|
||||
// void* == void
|
||||
Expect.identical(legacy(typeRep<void>()), typeRep<void>());
|
||||
Expect.identical(legacy(TYPE_REF<void>()), TYPE_REF<void>());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
// Tests runtime subtyping with explicit variance modifiers.
|
||||
|
||||
import 'dart:_runtime' show typeRep;
|
||||
import 'dart:_foreign_helper' show TYPE_REF;
|
||||
import 'dart:async' show FutureOr;
|
||||
|
||||
import 'runtime_utils.dart';
|
||||
@@ -27,163 +27,164 @@ class LegacyCovariant<T> {}
|
||||
|
||||
void main() {
|
||||
// Covariant<Lower> <: Covariant<Middle>
|
||||
checkProperSubtype(typeRep<Covariant<Lower>>(), typeRep<Covariant<Middle>>());
|
||||
checkProperSubtype(
|
||||
TYPE_REF<Covariant<Lower>>(), TYPE_REF<Covariant<Middle>>());
|
||||
|
||||
// Covariant<Middle> <: Covariant<Middle>
|
||||
checkSubtype(typeRep<Covariant<Middle>>(), typeRep<Covariant<Middle>>());
|
||||
checkSubtype(TYPE_REF<Covariant<Middle>>(), TYPE_REF<Covariant<Middle>>());
|
||||
|
||||
// Contravariant<Upper> <: Contravariant<Middle>
|
||||
checkProperSubtype(
|
||||
typeRep<Contravariant<Upper>>(), typeRep<Contravariant<Middle>>());
|
||||
TYPE_REF<Contravariant<Upper>>(), TYPE_REF<Contravariant<Middle>>());
|
||||
|
||||
// Contravariant<Middle> <: Contravariant<Middle>
|
||||
checkSubtype(
|
||||
typeRep<Contravariant<Middle>>(), typeRep<Contravariant<Middle>>());
|
||||
TYPE_REF<Contravariant<Middle>>(), TYPE_REF<Contravariant<Middle>>());
|
||||
|
||||
// Invariant<Middle> <: Invariant<Middle>
|
||||
checkSubtype(typeRep<Invariant<Middle>>(), typeRep<Invariant<Middle>>());
|
||||
checkSubtype(TYPE_REF<Invariant<Middle>>(), TYPE_REF<Invariant<Middle>>());
|
||||
|
||||
// Invariant<dynamic> <:> Invariant<Object?>
|
||||
checkMutualSubtype(
|
||||
typeRep<Invariant<dynamic>>(), typeRep<Invariant<Object?>>());
|
||||
TYPE_REF<Invariant<dynamic>>(), TYPE_REF<Invariant<Object?>>());
|
||||
|
||||
// Invariant<FutureOr<dynamic>> <:> Invariant<dynamic>
|
||||
checkMutualSubtype(
|
||||
typeRep<Invariant<FutureOr<dynamic>>>(), typeRep<Invariant<dynamic>>());
|
||||
TYPE_REF<Invariant<FutureOr<dynamic>>>(), TYPE_REF<Invariant<dynamic>>());
|
||||
|
||||
// Invariant<FutureOr<Null>> <:> Invariant<Future<Null>?>
|
||||
checkMutualSubtype(
|
||||
typeRep<Invariant<FutureOr<Null>>>(), typeRep<Invariant<Future<Null>?>>());
|
||||
checkMutualSubtype(TYPE_REF<Invariant<FutureOr<Null>>>(),
|
||||
TYPE_REF<Invariant<Future<Null>?>>());
|
||||
|
||||
// LegacyCovariant<Lower> <: LegacyCovariant<Middle>
|
||||
checkProperSubtype(
|
||||
typeRep<LegacyCovariant<Lower>>(), typeRep<LegacyCovariant<Middle>>());
|
||||
TYPE_REF<LegacyCovariant<Lower>>(), TYPE_REF<LegacyCovariant<Middle>>());
|
||||
|
||||
// List<Covariant<Lower>> <: Iterable<Covariant<Middle>>
|
||||
checkProperSubtype(typeRep<List<Covariant<Lower>>>(),
|
||||
typeRep<Iterable<Covariant<Middle>>>());
|
||||
checkProperSubtype(TYPE_REF<List<Covariant<Lower>>>(),
|
||||
TYPE_REF<Iterable<Covariant<Middle>>>());
|
||||
|
||||
// List<Contravariant<Upper>> <: Iterable<Contravariant<Middle>>
|
||||
checkProperSubtype(typeRep<List<Contravariant<Upper>>>(),
|
||||
typeRep<Iterable<Contravariant<Middle>>>());
|
||||
checkProperSubtype(TYPE_REF<List<Contravariant<Upper>>>(),
|
||||
TYPE_REF<Iterable<Contravariant<Middle>>>());
|
||||
|
||||
// List<Invariant<Middle>> <: Iterable<Invariant<Middle>>
|
||||
checkProperSubtype(typeRep<List<Invariant<Middle>>>(),
|
||||
typeRep<Iterable<Invariant<Middle>>>());
|
||||
checkProperSubtype(TYPE_REF<List<Invariant<Middle>>>(),
|
||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
||||
|
||||
// List<LegacyCovariant<Lower>> <: Iterable<LegacyCovariant<Middle>>
|
||||
checkProperSubtype(typeRep<List<LegacyCovariant<Lower>>>(),
|
||||
typeRep<Iterable<LegacyCovariant<Middle>>>());
|
||||
checkProperSubtype(TYPE_REF<List<LegacyCovariant<Lower>>>(),
|
||||
TYPE_REF<Iterable<LegacyCovariant<Middle>>>());
|
||||
|
||||
// String -> Covariant<Lower> <: String -> Covariant<Middle>
|
||||
checkProperSubtype(typeRep<Covariant<Lower> Function(String)>(),
|
||||
typeRep<Covariant<Middle> Function(String)>());
|
||||
checkProperSubtype(TYPE_REF<Covariant<Lower> Function(String)>(),
|
||||
TYPE_REF<Covariant<Middle> Function(String)>());
|
||||
|
||||
// Covariant<Upper> -> String <: Covariant<Middle> -> String
|
||||
checkProperSubtype(typeRep<String Function(Covariant<Upper>)>(),
|
||||
typeRep<String Function(Covariant<Middle>)>());
|
||||
checkProperSubtype(TYPE_REF<String Function(Covariant<Upper>)>(),
|
||||
TYPE_REF<String Function(Covariant<Middle>)>());
|
||||
|
||||
// String -> Contravariant<Upper> <: String -> Contravariant<Middle>
|
||||
checkProperSubtype(typeRep<Contravariant<Upper> Function(String)>(),
|
||||
typeRep<Contravariant<Middle> Function(String)>());
|
||||
checkProperSubtype(TYPE_REF<Contravariant<Upper> Function(String)>(),
|
||||
TYPE_REF<Contravariant<Middle> Function(String)>());
|
||||
|
||||
// Contravariant<Lower> -> String <: Contravariant<Middle> -> String
|
||||
checkProperSubtype(typeRep<String Function(Contravariant<Lower>)>(),
|
||||
typeRep<String Function(Contravariant<Middle>)>());
|
||||
checkProperSubtype(TYPE_REF<String Function(Contravariant<Lower>)>(),
|
||||
TYPE_REF<String Function(Contravariant<Middle>)>());
|
||||
|
||||
// String -> Invariant<Middle> <: String -> Invariant<Middle>
|
||||
checkSubtype(typeRep<String Function(Invariant<Middle>)>(),
|
||||
typeRep<String Function(Invariant<Middle>)>());
|
||||
checkSubtype(TYPE_REF<String Function(Invariant<Middle>)>(),
|
||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
||||
|
||||
// Invariant<Middle> -> String <: Invariant<Middle> -> String
|
||||
checkSubtype(typeRep<String Function(Invariant<Middle>)>(),
|
||||
typeRep<String Function(Invariant<Middle>)>());
|
||||
checkSubtype(TYPE_REF<String Function(Invariant<Middle>)>(),
|
||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
||||
|
||||
// String -> LegacyCovariant<Lower> <: String -> LegacyCovariant<Middle>
|
||||
checkProperSubtype(typeRep<LegacyCovariant<Lower> Function(String)>(),
|
||||
typeRep<LegacyCovariant<Middle> Function(String)>());
|
||||
checkProperSubtype(TYPE_REF<LegacyCovariant<Lower> Function(String)>(),
|
||||
TYPE_REF<LegacyCovariant<Middle> Function(String)>());
|
||||
|
||||
// LegacyCovariant<Upper> -> String <: LegacyCovariant<Middle> -> String
|
||||
checkProperSubtype(typeRep<String Function(LegacyCovariant<Upper>)>(),
|
||||
typeRep<String Function(LegacyCovariant<Middle>)>());
|
||||
checkProperSubtype(TYPE_REF<String Function(LegacyCovariant<Upper>)>(),
|
||||
TYPE_REF<String Function(LegacyCovariant<Middle>)>());
|
||||
|
||||
// Covariant<Upper> </: Covariant<Middle>
|
||||
checkSubtypeFailure(
|
||||
typeRep<Covariant<Upper>>(), typeRep<Covariant<Middle>>());
|
||||
TYPE_REF<Covariant<Upper>>(), TYPE_REF<Covariant<Middle>>());
|
||||
|
||||
// Contravariant<Lower> </: Contravariant<Middle>
|
||||
checkSubtypeFailure(
|
||||
typeRep<Contravariant<Lower>>(), typeRep<Contravariant<Middle>>());
|
||||
TYPE_REF<Contravariant<Lower>>(), TYPE_REF<Contravariant<Middle>>());
|
||||
|
||||
// Invariant<Upper> </: Invariant<Middle>
|
||||
checkSubtypeFailure(
|
||||
typeRep<Invariant<Upper>>(), typeRep<Invariant<Middle>>());
|
||||
TYPE_REF<Invariant<Upper>>(), TYPE_REF<Invariant<Middle>>());
|
||||
|
||||
// Invariant<Lower> </: Invariant<Middle>
|
||||
checkSubtypeFailure(
|
||||
typeRep<Invariant<Lower>>(), typeRep<Invariant<Middle>>());
|
||||
TYPE_REF<Invariant<Lower>>(), TYPE_REF<Invariant<Middle>>());
|
||||
|
||||
// LegacyCovariant<Upper> </: LegacyCovariant<Middle>
|
||||
checkSubtypeFailure(
|
||||
typeRep<LegacyCovariant<Upper>>(), typeRep<LegacyCovariant<Middle>>());
|
||||
TYPE_REF<LegacyCovariant<Upper>>(), TYPE_REF<LegacyCovariant<Middle>>());
|
||||
|
||||
// List<Covariant<Upper>> </: Iterable<Covariant<Middle>>
|
||||
checkSubtypeFailure(typeRep<List<Covariant<Upper>>>(),
|
||||
typeRep<Iterable<Covariant<Middle>>>());
|
||||
checkSubtypeFailure(TYPE_REF<List<Covariant<Upper>>>(),
|
||||
TYPE_REF<Iterable<Covariant<Middle>>>());
|
||||
|
||||
// List<Contravariant<Lower>> </: Iterable<Contravariant<Middle>>
|
||||
checkSubtypeFailure(typeRep<List<Contravariant<Lower>>>(),
|
||||
typeRep<Iterable<Contravariant<Middle>>>());
|
||||
checkSubtypeFailure(TYPE_REF<List<Contravariant<Lower>>>(),
|
||||
TYPE_REF<Iterable<Contravariant<Middle>>>());
|
||||
|
||||
// List<Invariant<Upper>> </: Iterable<Invariant<Middle>>
|
||||
checkSubtypeFailure(typeRep<List<Invariant<Upper>>>(),
|
||||
typeRep<Iterable<Invariant<Middle>>>());
|
||||
checkSubtypeFailure(TYPE_REF<List<Invariant<Upper>>>(),
|
||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
||||
|
||||
// List<Invariant<Lower>> </: Iterable<Invariant<Middle>>
|
||||
checkSubtypeFailure(typeRep<List<Invariant<Lower>>>(),
|
||||
typeRep<Iterable<Invariant<Middle>>>());
|
||||
checkSubtypeFailure(TYPE_REF<List<Invariant<Lower>>>(),
|
||||
TYPE_REF<Iterable<Invariant<Middle>>>());
|
||||
|
||||
// List<LegacyCovariant<Upper>> </: Iterable<LegacyCovariant<Middle>>
|
||||
checkSubtypeFailure(typeRep<List<LegacyCovariant<Upper>>>(),
|
||||
typeRep<Iterable<LegacyCovariant<Middle>>>());
|
||||
checkSubtypeFailure(TYPE_REF<List<LegacyCovariant<Upper>>>(),
|
||||
TYPE_REF<Iterable<LegacyCovariant<Middle>>>());
|
||||
|
||||
// String -> Covariant<Upper> </: String -> Covariant<Middle>
|
||||
checkSubtypeFailure(typeRep<Covariant<Upper> Function(String)>(),
|
||||
typeRep<Covariant<Middle> Function(String)>());
|
||||
checkSubtypeFailure(TYPE_REF<Covariant<Upper> Function(String)>(),
|
||||
TYPE_REF<Covariant<Middle> Function(String)>());
|
||||
|
||||
// Covariant<Lower> -> String </: Covariant<Middle> -> String
|
||||
checkSubtypeFailure(typeRep<String Function(Covariant<Lower>)>(),
|
||||
typeRep<String Function(Covariant<Middle>)>());
|
||||
checkSubtypeFailure(TYPE_REF<String Function(Covariant<Lower>)>(),
|
||||
TYPE_REF<String Function(Covariant<Middle>)>());
|
||||
|
||||
// String -> Contravariant<Lower> </: String -> Contravariant<Middle>
|
||||
checkSubtypeFailure(typeRep<Contravariant<Lower> Function(String)>(),
|
||||
typeRep<Contravariant<Middle> Function(String)>());
|
||||
checkSubtypeFailure(TYPE_REF<Contravariant<Lower> Function(String)>(),
|
||||
TYPE_REF<Contravariant<Middle> Function(String)>());
|
||||
|
||||
// Contravariant<Upper> -> String </: Contravariant<Middle> -> String
|
||||
checkSubtypeFailure(typeRep<String Function(Contravariant<Upper>)>(),
|
||||
typeRep<String Function(Contravariant<Middle>)>());
|
||||
checkSubtypeFailure(TYPE_REF<String Function(Contravariant<Upper>)>(),
|
||||
TYPE_REF<String Function(Contravariant<Middle>)>());
|
||||
|
||||
// String -> Invariant<Upper> </: String -> Invariant<Middle>
|
||||
checkSubtypeFailure(typeRep<Invariant<Upper> Function(String)>(),
|
||||
typeRep<Invariant<Middle> Function(String)>());
|
||||
checkSubtypeFailure(TYPE_REF<Invariant<Upper> Function(String)>(),
|
||||
TYPE_REF<Invariant<Middle> Function(String)>());
|
||||
|
||||
// Invariant<Upper> -> String </: Invariant<Middle> -> String
|
||||
checkSubtypeFailure(typeRep<String Function(Invariant<Upper>)>(),
|
||||
typeRep<String Function(Invariant<Middle>)>());
|
||||
checkSubtypeFailure(TYPE_REF<String Function(Invariant<Upper>)>(),
|
||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
||||
|
||||
// String -> Invariant<Lower> </: String -> Invariant<Middle>
|
||||
checkSubtypeFailure(typeRep<Invariant<Lower> Function(String)>(),
|
||||
typeRep<Invariant<Middle> Function(String)>());
|
||||
checkSubtypeFailure(TYPE_REF<Invariant<Lower> Function(String)>(),
|
||||
TYPE_REF<Invariant<Middle> Function(String)>());
|
||||
|
||||
// Invariant<Lower> -> String <: Invariant<Middle> -> String
|
||||
checkSubtypeFailure(typeRep<String Function(Invariant<Lower>)>(),
|
||||
typeRep<String Function(Invariant<Middle>)>());
|
||||
checkSubtypeFailure(TYPE_REF<String Function(Invariant<Lower>)>(),
|
||||
TYPE_REF<String Function(Invariant<Middle>)>());
|
||||
|
||||
// String -> LegacyCovariant<Upper> </: String -> LegacyCovariant<Middle>
|
||||
checkSubtypeFailure(typeRep<LegacyCovariant<Upper> Function(String)>(),
|
||||
typeRep<LegacyCovariant<Middle> Function(String)>());
|
||||
checkSubtypeFailure(TYPE_REF<LegacyCovariant<Upper> Function(String)>(),
|
||||
TYPE_REF<LegacyCovariant<Middle> Function(String)>());
|
||||
|
||||
// LegacyCovariant<Lower> -> String </: LegacyCovariant<Middle> -> String
|
||||
checkSubtypeFailure(typeRep<String Function(LegacyCovariant<Lower>)>(),
|
||||
typeRep<String Function(LegacyCovariant<Middle>)>());
|
||||
checkSubtypeFailure(TYPE_REF<String Function(LegacyCovariant<Lower>)>(),
|
||||
TYPE_REF<String Function(LegacyCovariant<Middle>)>());
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
// Tests the emission of explicit variance modifiers.
|
||||
|
||||
import 'dart:_runtime'
|
||||
show getGenericArgVariances, Variance, typeRep;
|
||||
import 'dart:_foreign_helper' show TYPE_REF;
|
||||
import 'dart:_runtime' show getGenericArgVariances, Variance;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
@@ -32,20 +32,20 @@ List? getVariances(Object type) {
|
||||
}
|
||||
|
||||
main() {
|
||||
Expect.listEquals([Variance.contravariant], getVariances(typeRep<A>())!);
|
||||
Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF<A>())!);
|
||||
|
||||
Expect.listEquals([Variance.covariant], getVariances(typeRep<B>())!);
|
||||
Expect.listEquals([Variance.covariant], getVariances(TYPE_REF<B>())!);
|
||||
|
||||
Expect.listEquals([Variance.invariant], getVariances(typeRep<C>())!);
|
||||
Expect.listEquals([Variance.invariant], getVariances(TYPE_REF<C>())!);
|
||||
|
||||
// Implicit variance is not emitted into the generated code.
|
||||
Expect.isNull(getVariances(typeRep<D>()));
|
||||
Expect.isNull(getVariances(TYPE_REF<D>()));
|
||||
|
||||
Expect.listEquals(
|
||||
[Variance.invariant, Variance.covariant, Variance.contravariant],
|
||||
getVariances(typeRep<E>())!);
|
||||
getVariances(TYPE_REF<E>())!);
|
||||
|
||||
Expect.listEquals([Variance.contravariant], getVariances(typeRep<F>())!);
|
||||
Expect.listEquals([Variance.contravariant], getVariances(TYPE_REF<F>())!);
|
||||
|
||||
Expect.listEquals([Variance.invariant], getVariances(typeRep<G>())!);
|
||||
Expect.listEquals([Variance.invariant], getVariances(TYPE_REF<G>())!);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user