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

Unified Diff: tests/language/const_error_multiply_initialized_test.dart

Issue 2901853002: Improve various old tests. (Closed)
Patch Set: Created 3 years, 7 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/language/black_listed_test.dart ('k') | tests/language/named_parameters_aggregated_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 104bed70c6103fb8e312f17986608d15cc0fb9a4..44ea44d9ca72cfd5c0122ae8ec195e94a7af00a6 100644
--- a/tests/language/const_error_multiply_initialized_test.dart
+++ b/tests/language/const_error_multiply_initialized_test.dart
@@ -2,27 +2,38 @@
// 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 {
+ // Since this field is final and already initialized, the specification says
+ // that a runtime error occurs when attempting to initialize it in the
+ // constructor. When used as a compile-time constant, this causes a
+ // compile-time error.
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
+
+ const C(
+ this. //# 01: compile-time error
+ this. //# 02: static type warning
+ x
+ )
+ : x = 2 //# 03: compile-time error
+ : x = 2 //# 04: static type warning
+ ;
+}
+
+instantiateC() {
+ const C(0); //# 01: continued
+ const C(0); //# 03: continued
+ new C(0);
}
main() {
- const C(); //# 01: continued
- Expect.throws(() => new C()); //# 02: continued
- const C(2); //# 03: continued
- Expect.throws(() => new C(2)); //# 04: continued
+ bool shouldThrow = false;
+ shouldThrow = true; //# 02: continued
+ shouldThrow = true; //# 04: continued
+ if (shouldThrow) {
+ Expect.throws(instantiateC);
+ } else {
+ instantiateC();
+ }
}
« no previous file with comments | « tests/language/black_listed_test.dart ('k') | tests/language/named_parameters_aggregated_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698