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

Unified Diff: tests/compiler/dart2js/type_variable_bound_test.dart

Issue 13133006: Check for cyclic type variable bounds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased + pull in PostProcess code. Created 7 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/type_test_helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/type_variable_bound_test.dart
diff --git a/tests/compiler/dart2js/type_variable_bound_test.dart b/tests/compiler/dart2js/type_variable_bound_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6dd38a8a8e765734c260b52dc6c37e67b6e5370f
--- /dev/null
+++ b/tests/compiler/dart2js/type_variable_bound_test.dart
@@ -0,0 +1,116 @@
+// Copyright (c) 2013, 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.
+
+import 'compiler_helper.dart';
+import "package:expect/expect.dart";
+
+compile(String source) {
+ Uri uri = new Uri('test:code');
+ var compiler = compilerFor(source, uri);
+ compiler.runCompiler(uri);
+ return compiler;
+}
+
+test1() {
+ var compiler = compile(r"""
+class A<T extends T> {}
+
+void main() {
+ new A();
+}
+""");
+
+ Expect.isFalse(compiler.compilationFailed);
+ Expect.isTrue(compiler.errors.isEmpty,
+ 'unexpected errors: ${compiler.errors}');
+ Expect.equals(1, compiler.warnings.length,
+ 'expected exactly one warning, but got ${compiler.warnings}');
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[0].message.kind);
+ Expect.equals("T", compiler.warnings[0].node.toString());
+}
+
+test2() {
+ var compiler = compile(r"""
+class B<T extends S, S extends T> {}
+
+void main() {
+ new B();
+}
+""");
+
+ Expect.isFalse(compiler.compilationFailed);
+ print(compiler.errors);
+ Expect.isTrue(compiler.errors.isEmpty, 'unexpected errors');
+ Expect.equals(2, compiler.warnings.length,
+ 'expected exactly one error, but got ${compiler.warnings}');
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[0].message.kind);
+ Expect.equals("T", compiler.warnings[0].node.toString());
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[1].message.kind);
+ Expect.equals("S", compiler.warnings[1].node.toString());
+}
+
+test3() {
+ var compiler = compile(r"""
+class C<T extends S, S extends U, U extends T> {}
+
+void main() {
+ new C();
+}
+""");
+
+ Expect.isFalse(compiler.compilationFailed);
+ print(compiler.errors);
+ Expect.isTrue(compiler.errors.isEmpty, 'unexpected errors');
+ Expect.equals(3, compiler.warnings.length,
+ 'expected exactly one error, but got ${compiler.warnings}');
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[0].message.kind);
+ Expect.equals("T", compiler.warnings[0].node.toString());
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[1].message.kind);
+ Expect.equals("S", compiler.warnings[1].node.toString());
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[2].message.kind);
+ Expect.equals("U", compiler.warnings[2].node.toString());
+}
+
+test4() {
+ var compiler = compile(r"""
+class D<T extends S, S extends U, U extends S> {}
+
+void main() {
+ new D();
+}
+""");
+
+ Expect.isFalse(compiler.compilationFailed);
+ print(compiler.errors);
+ Expect.isTrue(compiler.errors.isEmpty, 'unexpected errors');
+ Expect.equals(2, compiler.warnings.length,
+ 'expected exactly one error, but got ${compiler.warnings}');
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[0].message.kind);
+ Expect.equals("S", compiler.warnings[0].node.toString());
+
+ Expect.equals(MessageKind.CYCLIC_TYPE_VARIABLE,
+ compiler.warnings[1].message.kind);
+ Expect.equals("U", compiler.warnings[1].node.toString());
+}
+
+main() {
+ test1();
+ test2();
+ test3();
+ test4();
+}
« no previous file with comments | « tests/compiler/dart2js/type_test_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698