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

Unified Diff: tests/language/const_error_multiply_initialized_test.dart

Issue 1175073002: Report a compile-time error if a const field is multiply initialized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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/const_error_multiply_initialized_test.dart
diff --git a/tests/language/const_error_multiply_initialized_test.dart b/tests/language/const_error_multiply_initialized_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..896b1a3145345d5d3023128d8ae7a70bee8ab8c6
--- /dev/null
+++ b/tests/language/const_error_multiply_initialized_test.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2015, 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.
+
+// If a constant constructor contains an initializer, or an initializing
+// formal, for a final field which itself has an initializer at its
+// declaration, then a runtime error should occur if that constructor is
+// invoked using "new", but there should be no compile-time error. However, if
+// the constructor is invoked using "const", there should be a compile-time
+// error, since it is a compile-time error for evaluation of a constant object
+// to result in an uncaught exception.
+
+import "package:expect/expect.dart";
+
+class C {
+ final x = 1;
+ const C() : x = 2; /// 01: compile-time error
+ const C() : x = 2; /// 02: static type warning
+ const C(this.x); /// 03: compile-time error
+ const C(this.x); /// 04: static type warning
+}
+
+main() {
+ const C(); /// 01: continued
+ Expect.throws(() => new C()); /// 02: continued
+ const C(2); /// 03: continued
+ Expect.throws(() => new C(2)); /// 04: continued
+}
« no previous file with comments | « pkg/analyzer/test/generated/compile_time_error_code_test.dart ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698