Index: tests/language/void_type2_test.dart |
diff --git a/tests/language/void_type2_test.dart b/tests/language/void_type2_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db68e3d051a455c741803ad566129acaefc899bd |
--- /dev/null |
+++ b/tests/language/void_type2_test.dart |
@@ -0,0 +1,360 @@ |
+// 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. |
+ |
+void use(dynamic x) { } |
+ |
+void testVoidParam(void x) { |
+ x; /// param_stmt: ok |
+ true ? x : x; /// param_conditional: ok |
+ for (x; false; x) {} /// param_for: ok |
+ use(x); /// param_argument: static type warning |
+ use(x as Object); /// param_as: ok |
+ void y = x; /// param_void_init: static type warning |
+ dynamic z = x; /// param_dynamic_init: static type warning |
+ x is Object; /// param_is: static type warning |
+ throw x; /// param_throw: static type warning |
+ [x]; /// param_literal_list_init: static type warning |
+ var m1 = {4: x}; /// param_literal_map_value_init: static type warning |
+ var m2 = {x : 4}; /// param_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: x}; /// param_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = {x : 4}; /// param_literal_map_key_init2: static type warning |
+ x ?? 499; /// param_null_equals2: static type warning |
+ null ?? x; /// param_null_equals2: static type warning |
+ return x; /// param_return: static type warning |
+ while (x) {}; /// param_while: static type warning |
+ do {} while (x); /// param_do_while: static type warning |
+ for (var v in x) {} /// param_for_in: static type warning |
+ for (x in [1, 2]) {} /// param_for_in2: ok |
+ x += 1; /// param_plus_eq: static type warning |
+ x.toString(); /// param_toString: static type warning |
+ x?.toString(); /// param_null_dot: static type warning |
+ x..toString(); /// param_cascade: static type warning |
+} |
+ |
+void testVoidCall(void f()) { |
+ f(); /// call_stmt: ok |
+ true ? f() : f(); /// call_conditional: ok |
+ for (f(); false; f()) {} /// call_for: ok |
+ use(f()); /// call_argument: static type warning |
+ use(f() as Object); /// call_as: ok |
+ void y = f(); /// call_void_init: static type warning |
+ dynamic z = f(); /// call_dynamic_init: static type warning |
+ f() is Object; /// call_is: static type warning |
+ throw f(); /// call_throw: static type warning |
+ [f()]; /// call_literal_list_init: static type warning |
+ var m1 = {4: f() }; /// call_literal_map_value_init: static type warning |
+ var m2 = { f(): 4}; /// call_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: f() }; /// call_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = { f(): 4}; /// call_literal_map_key_init2: static type warning |
+ f() ?? 499; /// call_null_equals2: static type warning |
+ null ?? f(); /// call_null_equals2: static type warning |
+ return f(); /// call_return: static type warning |
+ while (f()) {}; /// call_while: static type warning |
+ do {} while (f()); /// call_do_while: static type warning |
+ for (var v in f()) {} /// call_for_in: static type warning |
+ f().toString(); /// call_toString: static type warning |
+ f()?.toString(); /// call_null_dot: static type warning |
+ f()..toString(); /// call_cascade: static type warning |
+} |
+ |
+void testVoidLocal() { |
+ void x; |
+ x = 42; /// local_assign: ok |
+ x; /// local_stmt: ok |
+ true ? x : x; /// local_conditional: ok |
+ for (x; false; x) {} /// local_for: ok |
+ use(x); /// local_argument: static type warning |
+ use(x as Object); /// local_as: ok |
+ void y = x; /// local_void_init: static type warning |
+ dynamic z = x; /// local_dynamic_init: static type warning |
+ x is Object; /// local_is: static type warning |
+ throw x; /// local_throw: static type warning |
+ [x]; /// local_literal_list_init: static type warning |
+ var m1 = {4: x}; /// local_literal_map_value_init: static type warning |
+ var m2 = {x : 4}; /// local_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: x}; /// local_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = {x : 4}; /// local_literal_map_key_init2: static type warning |
+ x ?? 499; /// local_null_equals2: static type warning |
+ null ?? x; /// local_null_equals2: static type warning |
+ return x; /// local_return: static type warning |
+ while (x) {}; /// local_while: static type warning |
+ do {} while (x); /// local_do_while: static type warning |
+ for (var v in x) {} /// local_for_in: static type warning |
+ for (x in [1, 2]) {} /// local_for_in2: ok |
+ x += 1; /// local_plus_eq: static type warning |
+ x.toString(); /// local_toString: static type warning |
+ x?.toString(); /// local_null_dot: static type warning |
+ x..toString(); /// local_cascade: static type warning |
+} |
+ |
+void testVoidFinalLocal() { |
+ final void x = null; |
+ x = 42; /// final_local_assign: static type warning |
+ x; /// final_local_stmt: ok |
+ true ? x : x; /// final_local_conditional: ok |
+ for (x; false; x) {} /// final_local_for: ok |
+ use(x); /// final_local_argument: static type warning |
+ use(x as Object); /// final_local_as: ok |
+ void y = x; /// final_local_void_init: static type warning |
+ dynamic z = x; /// final_local_dynamic_init: static type warning |
+ x is Object; /// final_local_is: static type warning |
+ throw x; /// final_local_throw: static type warning |
+ [x]; /// final_local_literal_list_init: static type warning |
+ var m1 = {4: x}; /// final_local_literal_map_value_init: static type warning |
+ var m2 = {x : 4}; /// final_local_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: x}; /// final_local_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = {x : 4}; /// final_local_literal_map_key_init2: static type warning |
+ x ?? 499; /// final_local_null_equals2: static type warning |
+ null ?? x; /// final_local_null_equals2: static type warning |
+ return x; /// final_local_return: static type warning |
+ while (x) {}; /// final_local_while: static type warning |
+ do {} while (x); /// final_local_do_while: static type warning |
+ for (var v in x) {} /// final_local_for_in: static type warning |
+ for (x in [1, 2]) {} /// final_local_for_in2: ok |
+ x += 1; /// final_local_plus_eq: static type warning |
+ x.toString(); /// final_local_toString: static type warning |
+ x?.toString(); /// final_local_null_dot: static type warning |
+ x..toString(); /// final_local_cascade: static type warning |
+} |
+ |
+void global; |
+void testVoidGlobal() { |
+ global; /// global_stmt: ok |
+ true ? global : global; /// global_conditional: ok |
+ for (global; false; global) {} /// global_for: ok |
+ use(global); /// global_argument: static type warning |
+ use(global as Object); /// global_as: ok |
+ void y = global; /// global_void_init: static type warning |
+ dynamic z = global; /// global_dynamic_init: static type warning |
+ global is Object; /// global_is: static type warning |
+ throw global; /// global_throw: static type warning |
+ [global]; /// global_literal_list_init: static type warning |
+ var m1 = {4: global }; /// global_literal_map_value_init: static type warning |
+ var m2 = { global: 4}; /// global_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: global }; /// global_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = { global: 4}; /// global_literal_map_key_init2: static type warning |
+ null ?? global; /// global_null_equals2: static type warning |
+ global ?? 499; /// global_null_equals2: static type warning |
+ return global; /// global_return: static type warning |
+ while (global) {}; /// global_while: static type warning |
+ do {} while (global); /// global_do_while: static type warning |
+ for (var v in global) {} /// global_for_in: static type warning |
+ for (global in [1, 2]) {} /// global_for_in2: ok |
+ global += 1; /// global_plus_eq: static type warning |
+ global.toString(); /// global_toString: static type warning |
+ global?.toString(); /// global_null_dot: static type warning |
+ global..toString(); /// global_cascade: static type warning |
+} |
+ |
+void testVoidConditional() { |
+ void x; |
+ (true ? x : x); /// conditional_parens: static type warning |
+ true ? x : x; /// conditional_stmt: ok |
+ true ? true ? x : x : true ? x : x; /// conditional_conditional: ok |
+ for (true ? x : x; false; true ? x : x) {} /// conditional_for: ok |
+ use(true ? x : x); /// conditional_argument: static type warning |
+ void y = true ? x : x; /// conditional_void_init: static type warning |
+ dynamic z = true ? x : x; /// conditional_dynamic_init: static type warning |
+ throw true ? x : x; /// conditional_throw: static type warning |
+ [true ? x : x]; /// conditional_literal_list_init: static type warning |
+ var m1 = {4: true ? x : x}; /// conditional_literal_map_value_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: true ? x : x}; /// conditional_literal_map_value_init2: static type warning |
+ null ?? true ? x : x; /// conditional_null_equals2: static type warning |
+ return true ? x : x; /// conditional_return: static type warning |
+ while (true ? x : x) {}; /// conditional_while: static type warning |
+ do {} while (true ? x : x); /// conditional_do_while: static type warning |
+ for (var v in true ? x : x) {} /// conditional_for_in: static type warning |
+ |
+ (true ? 499 : x); /// conditional2_parens: static type warning |
+ true ? 499 : x; /// conditional2_stmt: ok |
+ true ? true ? 499 : x : true ? 499 : x; /// conditional2_conditional: ok |
+ for (true ? 499 : x; false; true ? 499 : x) {} /// conditional2_for: ok |
+ use(true ? 499 : x); /// conditional2_argument: static type warning |
+ void y2 = true ? 499 : x; /// conditional2_void_init: static type warning |
+ dynamic z2 = true ? 499 : x; /// conditional2_dynamic_init: static type warning |
+ throw true ? 499 : x; /// conditional2_throw: static type warning |
+ [true ? 499 : x]; /// conditional2_literal_list_init: static type warning |
+ var m12 = {4: true ? 499 : x}; /// conditional2_literal_map_value_init: static type warning |
+ Map<dynamic, dynamic> m32 = {4: true ? 499 : x}; /// conditional2_literal_map_value_init2: static type warning |
+ null ?? true ? 499 : x; /// conditional2_null_equals2: static type warning |
+ return true ? 499 : x; /// conditional2_return: static type warning |
+ while (true ? 499 : x) {}; /// conditional2while: static type warning |
+ do {} while (true ? 499 : x); /// conditional2do_while: static type warning |
+ for (var v in true ? 499 : x) {} /// conditional2for_in: static type warning |
+ |
+ (true ? x : 499); /// conditional3_parens: static type warning |
+ true ? x : 499; /// conditional3_stmt: ok |
+ true ? true ? x : 499 : true ? x : 499; /// conditional3_conditional: ok |
+ for (true ? x : 499; false; true ? x : 499) {} /// conditional3_for: ok |
+ use(true ? x : 499); /// conditional3_argument: static type warning |
+ void y3 = true ? x : 499; /// conditional3_void_init: static type warning |
+ dynamic z3 = true ? x : 499; /// conditional3_dynamic_init: static type warning |
+ throw true ? x : 499; /// conditional3_throw: static type warning |
+ [true ? x : 499]; /// conditional3_literal_list_init: static type warning |
+ var m13 = {4: true ? x : 499 }; /// conditional3_literal_map_value_init: static type warning |
+ Map<dynamic, dynamic> m33 = {4: true ? x : 499 }; /// conditional3_literal_map_value_init2: static type warning |
+ null ?? true ? x : 499; /// conditional3_null_equals2: static type warning |
+ return true ? x : 499; /// conditional3_return: static type warning |
+ while (true ? x : 499) {}; /// conditional_while: static type warning |
+ do {} while (true ? x : 499); /// conditional_do_while: static type warning |
+ for (var v in true ? x : 499) {} /// conditional_for_in: static type warning |
+} |
+ |
+ |
+class A<T> { |
+ T x; |
+ |
+ void foo() {} |
+} |
+ |
+class B implements A<void> { |
+ void x; |
+ |
+ int foo() => 499; |
+ |
+ void forInTest() { |
+ for (x in <void>[]) {} /// instance2_for_in2: static type warning |
+ for (x in [1, 2]) {} /// instance2_for_in3: ok |
+ } |
+} |
+ |
+class C implements A<void> { |
+ void get x => null; |
+ set x(void y) {} |
+ |
+ void forInTest() { |
+ for (x in <void>[]) {} /// instance3_for_in2: static type warning |
+ for (x in [1, 2]) {} /// instance3_for_in3: ok |
+ } |
+} |
+ |
+ |
+void testInstanceField() { |
+ A<void> a = new A<void>(); |
+ a.x = 499; /// field_assign: ok |
+ a.x; /// instance_stmt: ok |
+ true ? a.x : a.x; /// instance_conditional: ok |
+ for (a.x; false; a.x) {} /// instance_for: ok |
+ use(a.x); /// instance_argument: static type warning |
+ use(a.x as Object); /// instance_as: ok |
+ void y = a.x; /// instance_void_init: static type warning |
+ dynamic z = a.x; /// instance_dynamic_init: static type warning |
+ a.x is Object; /// instance_is: static type warning |
+ throw a.x; /// instance_throw: static type warning |
+ [a.x]; /// instance_literal_list_init: static type warning |
+ var m1 = {4: a.x}; /// instance_literal_map_value_init: static type warning |
+ var m2 = { a.x : 4}; /// instance_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: a.x}; /// instance_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = { a.x : 4}; /// instance_literal_map_key_init2: static type warning |
+ null ?? a.x; /// instance_null_equals2: static type warning |
+ a.x ?? 499; /// instance_null_equals2: static type warning |
+ return a.x; /// instance_return: static type warning |
+ while (a.x) {}; /// instance_while: static type warning |
+ do {} while (a.x); /// instance_do_while: static type warning |
+ for (var v in a.x) {} /// instance_for_in: static type warning |
+ a.x += 1; /// instance_plus_eq: static type warning |
+ a.x.toString(); /// instance_toString: static type warning |
+ a.x?.toString(); /// instance_null_dot: static type warning |
+ a.x..toString(); /// instance_cascade: static type warning |
+ |
+ B b = new B(); |
+ b.x = 42; /// field_assign2: ok |
+ b.x; /// instance2_stmt: ok |
+ true ? b.x : b.x; /// instance2_conditional: ok |
+ for (b.x; false; b.x) {} /// instance2_for: ok |
+ use(b.x); /// instance2_argument: static type warning |
+ use(b.x as Object); /// instance2_as: ok |
+ void y2 = b.x; /// instance2_void_init: static type warning |
+ dynamic z2 = b.x; /// instance2_dynamic_init: static type warning |
+ b.x is Object; /// instance2_is: static type warning |
+ throw b.x; /// instance2_throw: static type warning |
+ [b.x]; /// instance2_literal_list_init: static type warning |
+ var m12 = {4: b.x}; /// instance2_literal_map_value_init: static type warning |
+ var m22 = { b.x : 4}; /// instance2_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m32 = {4: b.x}; /// instance2_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m42 = { b.x : 4}; /// instance2_literal_map_key_init2: static type warning |
+ null ?? b.x; /// instance2_null_equals2: static type warning |
+ b.x ?? 499; /// instance2_null_equals2: static type warning |
+ return b.x; /// instance2_return: static type warning |
+ while (b.x) {}; /// instance2_while: static type warning |
+ do {} while (b.x); /// instance2_do_while: static type warning |
+ for (var v in b.x) {} /// instance2_for_in: static type warning |
+ b.forInTest(); |
+ b.x += 1; /// instance2_plus_eq: static type warning |
+ b.x.toString(); /// instance2_toString: static type warning |
+ b.x?.toString(); /// instance2_null_dot: static type warning |
+ b.x..toString(); /// instance2_cascade: static type warning |
+ |
+ C c = new C(); |
+ c.x = 32; /// setter_assign: ok |
+ c.x; /// instance3_stmt: ok |
+ true ? c.x : c.x; /// instance3_conditional: ok |
+ for (c.x; false; c.x) {} /// instance3_for: ok |
+ use(c.x); /// instance3_argument: static type warning |
+ use(c.x as Object); /// instance3_as: ok |
+ void y3 = c.x; /// instance3_void_init: static type warning |
+ dynamic z3 = c.x; /// instance3_dynamic_init: static type warning |
+ c.x is Object; /// instance3_is: static type warning |
+ throw c.x; /// instance3_throw: static type warning |
+ [c.x]; /// instance3_literal_list_init: static type warning |
+ var m13 = {4: c.x}; /// instance3_literal_map_value_init: static type warning |
+ var m23 = { c.x : 4}; /// instance3_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m33 = {4: c.x}; /// instance3_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m43 = { c.x : 4}; /// instance3_literal_map_key_init2: static type warning |
+ null ?? c.x; /// instance3_null_equals2: static type warning |
+ c.x ?? 499; /// instance3_null_equals2: static type warning |
+ return c.x; /// instance3_return: static type warning |
+ while (c.x) {}; /// instance3_while: static type warning |
+ do {} while (c.x); /// instance3_do_while: static type warning |
+ for (var v in c.x) {} /// instance3_for_in: static type warning |
+ c.forInTest(); |
+ c.x += 1; /// instance3_plus_eq: static type warning |
+ c.x.toString(); /// instance3_toString: static type warning |
+ c.x?.toString(); /// instance3_null_dot: static type warning |
+ c.x..toString(); /// instance3_cascade: static type warning |
+} |
+ |
+void testParenthesized() { |
+ void x; |
+ (x); /// paren_stmt: ok |
+ true ? (x) : (x); /// paren_conditional: ok |
+ for ((x); false; (x)) {} /// paren_for: ok |
+ use((x)); /// paren_argument: static type warning |
+ use((x) as Object); /// paren_as: ok |
+ void y = (x); /// paren_void_init: static type warning |
+ dynamic z = (x); /// paren_dynamic_init: static type warning |
+ (x) is Object; /// paren_is: static type warning |
+ throw (x); /// paren_throw: static type warning |
+ [(x)]; /// paren_literal_list_init: static type warning |
+ var m1 = {4: (x) }; /// paren_literal_map_value_init: static type warning |
+ var m2 = { (x): 4}; /// paren_literal_map_key_init: static type warning |
+ Map<dynamic, dynamic> m3 = {4: (x) }; /// paren_literal_map_value_init2: static type warning |
+ Map<dynamic, dynamic> m4 = { (x): 4}; /// paren_literal_map_key_init2: static type warning |
+ (x) ?? 499; /// paren_null_equals2: static type warning |
+ null ?? (x); /// paren_null_equals2: static type warning |
+ return (x); /// paren_return: static type warning |
+ while ((x)) {}; /// paren_while: static type warning |
+ do {} while ((x)); /// paren_do_while: static type warning |
+ for (var v in (x)) {} /// paren_for_in: static type warning |
+ (x).toString(); /// paren_toString: static type warning |
+ (x)?.toString(); /// paren_null_dot: static type warning |
+ (x)..toString(); /// paren_cascade: static type warning |
+} |
+ |
+main() { |
+ try { |
+ testVoidParam(499); |
+ testVoidCall(() {}); |
+ testVoidLocal(); |
+ testVoidFinalLocal(); |
+ testVoidConditional(); |
+ testInstanceField(); |
+ testParenthesized(); |
+ } catch (e) { |
+ // Silently eat all dynamic errors. |
+ // This test is only testing static warnings. |
+ } |
+} |