Files
sdk/tests/compiler/dartdevc_native/runtime_utils.dart
T
Nicholas Shahan d166b0be1c [dartdevc] Reorganize and add some NNBD subtype test cases
- The strong and weak tests are still identical because weak mode still executes
  with the strong mode semantics.
- This is organization prep to make it easier to all what cases are covered and
  what changes when I land the weak mode support.

Change-Id: I4b067cee9a4f88b417587f1bf6a42c15fa4f624e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123005
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2019-10-25 23:51:02 +00:00

81 lines
2.9 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// 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' as dart;
import 'package:expect/expect.dart';
// The runtime representation of the void type.
final voidType = dart.wrapType(dart.void_);
// Returns sWrapped<tWrapped> as a wrapped type.
Type generic1(Type sWrapped, Type tWrapped) {
var s = dart.unwrapType(sWrapped);
var t = dart.unwrapType(tWrapped);
var sGeneric = dart.getGenericClass(s);
return dart.wrapType(JS('', '#(#)', sGeneric, t));
}
// Returns sWrapped<tWrapped, rWrapped> as a wrapped type.
Type generic2(Type sWrapped, Type tWrapped, Type rWrapped) {
var s = dart.unwrapType(sWrapped);
var t = dart.unwrapType(tWrapped);
var r = dart.unwrapType(rWrapped);
var sGeneric = dart.getGenericClass(s);
return dart.wrapType(JS('', '#(#, #)', sGeneric, t, r));
}
// Returns a function type of argWrapped -> returnWrapped as a wrapped type.
Type function1(Type returnWrapped, Type argWrapped) {
var returnType = dart.unwrapType(returnWrapped);
var argType = dart.unwrapType(argWrapped);
var fun = dart.fnType(returnType, [argType]);
return dart.wrapType(fun);
}
// Returns a function type with a bounded type argument that takes no argument
// and returns void as a wrapped type.
Type genericFunction(Type boundWrapped) => dart.wrapType(dart.gFnType(
(T) => [dart.VoidType, []], (T) => [dart.unwrapType(boundWrapped)]));
// Returns a function type with a bounded generic return type of
// <T extends boundWrapped> argWrapped -> T as a wrapped type.
Type functionGenericReturn(Type boundWrapped, Type argWrapped) =>
dart.wrapType(dart.gFnType(
(T) => [
T,
[dart.unwrapType(argWrapped)]
],
(T) => [dart.unwrapType(boundWrapped)]));
// Returns a function with a bounded generic argument type of
// <T extends boundWrapped> T -> returnWrapped as a wrapped type.
Type functionGenericArg(Type boundWrapped, Type returnWrapped) =>
dart.wrapType(dart.gFnType(
(T) => [
dart.unwrapType(returnWrapped),
[T]
],
(T) => [dart.unwrapType(boundWrapped)]));
void checkSubtype(Type sWrapped, Type tWrapped) {
var s = dart.unwrapType(sWrapped);
var t = dart.unwrapType(tWrapped);
Expect.isTrue(dart.isSubtypeOf(s, t), '$s should be subtype of $t.');
}
void checkProperSubtype(Type sWrapped, Type tWrapped) {
var s = dart.unwrapType(sWrapped);
var t = dart.unwrapType(tWrapped);
Expect.isTrue(dart.isSubtypeOf(s, t), '$s should be subtype of $t.');
checkSubtypeFailure(tWrapped, sWrapped);
}
void checkSubtypeFailure(Type sWrapped, Type tWrapped) {
var s = dart.unwrapType(sWrapped);
var t = dart.unwrapType(tWrapped);
Expect.isFalse(dart.isSubtypeOf(s, t), '$s should not be subtype of $t.');
}