Do simple type tests using T in non-external methods in js_interop_non_external_test
It's possible with changes in how we handle generics in
DDC that T might not be the type we expect at runtime. So,
we should test to make sure that it is by doing some simple
type tests in the body of non-external methods of JS interop
classes.
Change-Id: I0220b2bced4e5769e3728833204dfb3ac19f26d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378572
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
diff --git a/tests/dartdevc/js_interop_non_external_lib.dart b/tests/dartdevc/js_interop_non_external_lib.dart
index 42dfecb..ef6eaa9 100644
--- a/tests/dartdevc/js_interop_non_external_lib.dart
+++ b/tests/dartdevc/js_interop_non_external_lib.dart
@@ -9,17 +9,24 @@
@JS()
library js_interop_non_external_lib;
+import 'package:expect/expect.dart';
import 'package:js/js.dart';
@JS('JSClass')
-class OtherJSClass<T> {
+class OtherJSClass<T extends num> {
external OtherJSClass.cons(T t);
factory OtherJSClass(T t) {
+ // Do a simple test using T.
+ Expect.type<T>(t);
+ Expect.notType<T>('');
field = 'unnamed';
return OtherJSClass.cons(t);
}
factory OtherJSClass.named(T t) {
+ // Do a simple test using T.
+ Expect.type<T>(t);
+ Expect.notType<T>('');
field = 'named';
return OtherJSClass.cons(t);
}
@@ -37,5 +44,10 @@
static String method() => field;
- static T genericMethod<T>(T t) => t;
+ static T genericMethod<T extends num>(T t) {
+ // Do a simple test using T.
+ Expect.type<T>(t);
+ Expect.notType<T>('');
+ return t;
+ }
}
diff --git a/tests/dartdevc/js_interop_non_external_test.dart b/tests/dartdevc/js_interop_non_external_test.dart
index 6e1450b..25cf658 100644
--- a/tests/dartdevc/js_interop_non_external_test.dart
+++ b/tests/dartdevc/js_interop_non_external_test.dart
@@ -7,6 +7,7 @@
@JS()
library js_interop_non_external_test;
+import 'package:expect/expect.dart';
import 'package:expect/minitest.dart'; // ignore: deprecated_member_use_from_same_package
import 'package:js/js.dart';
@@ -41,7 +42,12 @@
static String method() => field;
- static T genericMethod<T>(T t) => t;
+ static T genericMethod<T extends num>(T t) {
+ // Do a simple test using T.
+ Expect.type<T>(t);
+ Expect.notType<T>('');
+ return t;
+ }
}
@JS('JSClass')
@@ -103,10 +109,10 @@
// Test methods and their tear-offs.
expect(JSClass.method(), JSClass.field);
- expect(JSClass.genericMethod(JSClass.field), JSClass.field);
+ expect(JSClass.genericMethod(0), 0);
expect((JSClass.method)(), JSClass.field);
- expect((JSClass.genericMethod)(JSClass.field), JSClass.field);
+ expect((JSClass.genericMethod)(0), 0);
// Briefly check that other interop classes work too.
expect(StaticInterop.field, '');
@@ -133,17 +139,17 @@
OtherJSClass<int>(0);
expect(OtherJSClass.field, 'unnamed');
- OtherJSClass.named('');
+ OtherJSClass.named(0);
expect(OtherJSClass.field, 'named');
- OtherJSClass<bool>.redirecting(true);
+ OtherJSClass<double>.redirecting(0.1);
expect(OtherJSClass.field, 'unnamed');
(OtherJSClass.cons)(0);
(OtherJSClass<int>.new)(0);
expect(OtherJSClass.field, 'unnamed');
- (OtherJSClass.named)('');
+ (OtherJSClass.named)(0);
expect(OtherJSClass.field, 'named');
- (OtherJSClass<bool>.redirecting)(true);
+ (OtherJSClass<double>.redirecting)(0.1);
expect(OtherJSClass.field, 'unnamed');
expect(OtherJSClass.getSet, OtherJSClass.field);
@@ -151,10 +157,10 @@
expect(OtherJSClass.field, 'set');
expect(OtherJSClass.method(), OtherJSClass.field);
- expect(OtherJSClass.genericMethod(OtherJSClass.field), OtherJSClass.field);
+ expect(OtherJSClass.genericMethod(0), 0);
expect((OtherJSClass.method)(), OtherJSClass.field);
- expect((OtherJSClass.genericMethod)(OtherJSClass.field), OtherJSClass.field);
+ expect((OtherJSClass.genericMethod)(0), 0);
}
void main() {