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

Unified Diff: tests/language/void_type4_test.dart

Issue 2707933002: Tests for `void`.
Patch Set: Address comments. Created 3 years, 10 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: tests/language/void_type4_test.dart
diff --git a/tests/language/void_type4_test.dart b/tests/language/void_type4_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f0e6e68f53efa250b4a71373e8b22be3bbeb3e11
--- /dev/null
+++ b/tests/language/void_type4_test.dart
@@ -0,0 +1,125 @@
+// Copyright (c) 2017, 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.
+
+// Dart test for type checks involving the void type.
Leaf 2017/02/23 21:30:52 Are these strong mode, Dart 1.0, or both?
eernst 2017/07/10 16:05:34 In Dart 1.x it is a static warning if m2 overrides
+
+import 'package:expect/expect.dart';
+
+use<T>(T x) {}
+
+class A<T> {
+ T x;
+ Object y;
Leaf 2017/02/23 21:30:52 Is it worth also have a dynamic version to make it
+ int z;
+
+ T foo() => null;
+ void bar() {}
+ void gee(T x) {}
+
+ f(A<Object> a) {}
+ g(A<void> a) {}
+ h(A<T> a) {}
+}
+
+class B implements A<Object> {
+ void /// 00: error
eernst 2017/07/10 16:05:34 This would be a static warning for Dart 1.x.
+ /* /// 00: continued
+ var
+ */ /// 00: continued
+ x;
+
+ void /// 00b: error
eernst 2017/07/10 16:05:34 This would be a static warning for Dart 1.x.
+ /* /// 00b: continued
+ var
+ */ /// 00b: continued
+ y;
+
+ void /// 00c: error
eernst 2017/07/10 16:05:34 This would be a static warning for Dart 1.x.
+ /* /// 00c: continued
+ int
+ */ /// 00c: continued
+ z;
+
+ // Overriding an Object function with a void function is an error.
+ void /// 01: error
eernst 2017/07/10 16:05:34 This would be a static warning for Dart 1.x.
+ foo() => null;
+
+ int bar() => 499;
+ void gee(void x) {}
+ f(A<void> a) {}
+ g(A<void> a) {}
+ h(A<void> a) {}
eernst 2017/07/10 16:05:34 (Just noting that these overriding declarations ar
+}
+
+class C implements A<void> {
+ void x;
+ Object y;
+ int z;
+
+ void foo() {}
+ void bar() {}
+ void gee(void x) {
+ use(x); /// 03: error
+ }
+
+ f(C c) {}
+ g(C c) {}
+ h(C c) {}
+}
+
+class D implements A<void> {
+ Object x; /// 04: ok? should be ok, but the setter goes from void to Object.
Leaf 2017/02/23 21:30:53 I think not ok, at least not as we've formulated t
eernst 2017/07/11 08:45:43 The informal spec of generalized void is built on
+ Object y;
+ int z;
+
+ Object foo() => null;
+ void bar() {}
+ void gee(
+ Object /// 05: error
eernst 2017/07/11 08:45:43 We will only get an error here if we introduce a n
+ x) {}
+
+ f(A<Object> a) {}
+ g(
+ A<Object> /// 06: error
eernst 2017/07/11 08:45:43 This parameter type was declared as `A<void>` in `
+ a) {}
+ h(
+ A<Object> /// 07: error
eernst 2017/07/11 08:45:43 This parameter type was declared as `A<T>` in `A<T
+ a) {}
+}
+
+void instantiateClasses() {
+ var a = new A<void>();
+ var b = new B();
+ var c = new C();
+ var d = new D();
+
+ a.foo();
+ b.foo();
+ c.foo();
+ d.foo();
+ a.bar();
+ b.bar();
+ c.bar();
+ d.bar();
+ a.gee(499);
+ b.gee(499);
+ c.gee(499);
+ d.gee(499);
+}
+
+void testAssignments() {
+ A<void> a1 = new A<Object>();
+ A<Object> a2 = new
+ A
+ <void> /// implicit_downcast: error
Leaf 2017/02/23 21:30:53 What does this mean? Implicit downcasts aren't er
eernst 2017/07/11 08:45:43 This can only be an error with full support for vo
+ ();
+ A a3 = new A<void>(); /// raw_assignment: ok?
Leaf 2017/02/23 21:30:53 There should be no difference between this one and
eernst 2017/07/11 08:45:43 Since we don't have voidness preservation at this
+ A<dynamic> a4 = new A<void>(); /// A_dynamic_assignment: ok?
Leaf 2017/02/23 21:30:53 ditto.
eernst 2017/07/11 08:45:43 Same as line 117.
+ dynamic a5 = new A<void>(); /// dynamic_assignment: ok?
eernst 2017/07/11 08:45:43 Since we don't have voidness preservation at this
+}
+
+main() {
+ instantiateClasses();
+ testAssignments();
+}

Powered by Google App Engine
This is Rietveld 408576698