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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Dart test for type checks involving the void type.
6
7 import 'package:expect/expect.dart';
8
9 use<T>(T x) {}
10
11 class A<T> {
12 T x;
13 Object y;
14 int z;
15
16 T foo() => null;
17 void bar() {}
18 void gee(T x) {}
19
20 f(A<Object> a) {}
21 g(A<void> a) {}
22 h(A<T> a) {}
23 }
24
25 class B implements A<Object> {
26 var
27 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.
28 x;
29
30 var
31 void /// 00b: error
32 y;
33
34 int
35 void /// 00c: error
36 z;
37
38 void /// 01: error
39 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.
40
41 int bar() => 499;
42 void gee(
43 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.
44 x) {}
45
46 f(A<void> a) {}
47 g(A<void> a) {}
48 h(A<void> a) {}
49 }
50
51 class C implements A<void> {
52 void x;
53 Object y;
54 int z;
55
56 void foo() {}
57 void bar() {}
58 void gee(void x) {
59 use(x); /// 03: error
60 }
61
62 f(C c) {}
63 g(C c) {}
64 h(C c) {}
65 }
66
67 class D implements A<void> {
68 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
69 Object y;
70 int z;
71
72 Object foo() => null;
73 void bar() {}
74 void gee(
75 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
76 x) {}
77
78 f(A<Object> a) {}
79 g(
80 A<Object> /// 06: error
81 a) {}
82 h(
83 A<Object> /// 07: error
84 a) {}
85 }
86
87 void instantiateClasses() {
88 var a = new A<void>();
89 var b = new B();
90 var c = new C();
91 var d = new D();
92
93 a.foo();
94 b.foo();
95 c.foo();
96 d.foo();
97 a.bar();
98 b.bar();
99 c.bar();
100 d.bar();
101 a.gee(499);
102 b.gee(499);
103 c.gee(499);
104 d.gee(499);
105 }
106
107 void testAssignments() {
108 A<void> a1 = new A<Object>();
109 A<Object> a2 = new
110 A
111 <void> /// implicit_downcast: error
112 ();
eernst 2017/02/21 13:39:13 Yes, I think we should let the special treatment o
113 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
114 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
115 }
116
117 main() {
118 instantiateClasses();
119 testAssignments();
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698