Index: tests/language/lazy_static8_test.dart |
diff --git a/tests/language/lazy_static8_test.dart b/tests/language/lazy_static8_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..812219f7be0f4dd78d7ea0ac496a8c3f50be50d8 |
--- /dev/null |
+++ b/tests/language/lazy_static8_test.dart |
@@ -0,0 +1,73 @@ |
+// 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. |
+ |
+import "package:expect/expect.dart"; |
+ |
+// Test re-entrant initializer - calls throw CyclicInitializationError. |
+ |
+var trace; |
+ |
+final foo = bar; |
+ |
+get bar { |
+ trace.add('bar'); |
+ try { |
+ return foo ?? 1; |
+ } catch (e) { |
+ trace.add(e is CyclicInitializationError); |
+ } |
+ try { |
+ return foo ?? 2; |
+ } catch (e) { |
+ trace.add(e is CyclicInitializationError); |
+ } |
+ return 42; |
+} |
+ |
+void testTopLevel() { |
+ trace = []; |
+ var result = foo; |
+ Expect.equals(42, result); |
+ Expect.equals('bar,true,true', trace.join(',')); |
+ trace = []; |
+ result = foo; |
+ Expect.equals(42, result); |
+ Expect.equals('', trace.join(',')); |
+ |
+} |
+ |
+class X { |
+ static final foo = X.bar; |
+ |
+ static get bar { |
+ trace.add('X.bar'); |
+ try { |
+ return foo ?? 1; |
+ } catch (e) { |
+ trace.add(e is CyclicInitializationError); |
+ } |
+ try { |
+ return foo ?? 2; |
+ } catch (e) { |
+ trace.add(e is CyclicInitializationError); |
+ } |
+ return 49; |
+ } |
+} |
+ |
+void testClassStatic() { |
+ trace = []; |
+ var result = X.foo; |
+ Expect.equals(49, result); |
+ Expect.equals('X.bar,true,true', trace.join(',')); |
+ trace = []; |
+ result = X.foo; |
+ Expect.equals(49, result); |
+ Expect.equals('', trace.join(',')); |
+} |
+ |
+main() { |
+ testTopLevel(); |
+ testClassStatic(); |
+} |