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

Unified Diff: tests/language/void_type4_test.dart

Issue 2707933002: Tests for `void`.
Patch Set: More tests. 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..8d1c2ea525788d2467edfd4341b8dbccced4d95a
--- /dev/null
+++ b/tests/language/void_type4_test.dart
@@ -0,0 +1,120 @@
+// 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.
+
+import 'package:expect/expect.dart';
+
+use<T>(T x) {}
+
+class A<T> {
+ T x;
+ Object y;
+ 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> {
+ var
+ void /// 00: error
Lasse Reichstein Nielsen 2017/02/21 09:37:04 That looks wrong. "var void x;" isn't valid syntax
floitsch 2017/02/22 14:44:43 Done.
+ x;
+
+ var
+ void /// 00b: error
+ y;
+
+ int
+ void /// 00c: error
+ z;
+
+ void /// 01: error
+ foo() => null;
Lasse Reichstein Nielsen 2017/02/21 09:37:04 Say what the problem here is. It's overriding an O
floitsch 2017/02/22 14:44:43 Done.
+
+ int bar() => 499;
+ void gee(
+ void /// 02: error
Lasse Reichstein Nielsen 2017/02/21 09:37:04 I don't think this should be an error. It's overr
floitsch 2017/02/22 14:44:43 right. done.
+ x) {}
+
+ f(A<void> a) {}
+ g(A<void> a) {}
+ h(A<void> a) {}
+}
+
+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.
Lasse Reichstein Nielsen 2017/02/21 09:37:04 The getter is fine, but the setter isn't. This is
eernst 2017/02/21 13:39:12 We have the following overriding relationship: A
+ Object y;
+ int z;
+
+ Object foo() => null;
+ void bar() {}
+ void gee(
+ Object /// 05: error
Lasse Reichstein Nielsen 2017/02/21 09:37:04 This is effectively the same signature as the sett
eernst 2017/02/21 13:39:13 Same issue: If we use Dart 1 overriding rules then
+ x) {}
+
+ f(A<Object> a) {}
+ g(
+ A<Object> /// 06: error
+ a) {}
+ h(
+ A<Object> /// 07: error
+ 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
+ ();
eernst 2017/02/21 13:39:13 Yes, I think we should let the special treatment o
+ A a3 = new A<void>(); /// raw_assignment: ok?
eernst 2017/02/21 13:39:13 In Dart 1 the type annotation `A` is definitely `A
+ A<dynamic> a4 = new A<void>(); /// dynamic_assignment: ok?
Lasse Reichstein Nielsen 2017/02/21 09:37:04 So, basically, the question is whether dynamic is
eernst 2017/02/21 13:39:13 Agreed, I'd want to make this an error, but the re
floitsch 2017/02/22 14:44:43 What about `dynamic a5 = new A<void>()` then? Adde
Lasse Reichstein Nielsen 2017/06/02 11:14:23 I want to say "allowed". Here you are not casting
+}
+
+main() {
+ instantiateClasses();
+ testAssignments();
+}

Powered by Google App Engine
This is Rietveld 408576698