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

Unified Diff: tests/language/implicit_setter_test.dart

Issue 26682002: Add test for new final-field implicit setter semantics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mark static warning as such. Created 7 years, 2 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 | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/implicit_setter_test.dart
diff --git a/tests/language/implicit_setter_test.dart b/tests/language/implicit_setter_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ff940bf4e1f8f6b41dfc8dd1cfcae17ed784bfa5
--- /dev/null
+++ b/tests/language/implicit_setter_test.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
ngeoffray 2013/10/17 09:15:23 2012 -> 2013
+// 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 of final fields generating implicit setters that throw.
+
+String x = "toplevel"; // Should never be read in this test.
+
+class B {
+ var x = 37;
+}
+
+class C extends B {
+ final x = 42;
+
+ // Local access should work the same as direct access.
+ get cx => x;
+ void set cx(value) {
+ x = value; /// 02: static type warning
+ erase(this).x = value; // but crash even if the direct setting is omitted.
ngeoffray 2013/10/17 09:15:23 Why isn't this a /// 03: runtime error?
+ }
+
+ // Super access should work.
+ get bx => super.x;
+ void set bx(value) { super.x = value; }
+
+ noSuchMethod(i) => "noSuchMethod"; // Should never be called in this test.
+}
+
+// Class with only final field has setter in implicit interface.
+class A {
+ final int x = 42;
+}
+
+// Should get warning because the implicit interface contains the setter,
+// and this non-abstract class doesn't.
+class AI
+ implements A /// 01: static type warning
+{
+ int get x => 37;
+}
+
+// Erases static type information. Used to avoid *static* warnings when
+// using a setter for a final field.
+erase(x) => x;
+
+void main() {
+ Expect.equals(42, new C().x);
+ Expect.throws(() { erase(new C()).x = 10; });
+ Expect.equals(42, new C().cx);
+ Expect.throws(() { erase(new C()).cx = 10; });
+ Expect.equals(37, new C().bx);
+ Expect.equals(10, (erase(new C())..bx = 10).bx);
+
+ Expect.equals(42, new A().x);
+ Expect.throws(() { erase(new A()).x = 10; });
+ Expect.equals(37, new AI().x);
+ Expect.throws(() { erase(new AI()).x = 10; });
+
+ Expect.equals("toplevel", x); // Should not have changed.
+}
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698