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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 // Test of final fields generating implicit setters that throw.
8
9 String x = "toplevel"; // Should never be read in this test.
10
11 class B {
12 var x = 37;
13 }
14
15 class C extends B {
16 final x = 42;
17
18 // Local access should work the same as direct access.
19 get cx => x;
20 void set cx(value) { x = value; } // Should throw if used.
Lasse Reichstein Nielsen 2013/10/09 11:08:39 I think this line should be a static warning becau
21
22 // Super access should work.
23 get bx => super.x;
24 void set bx(value) { super.x = value; }
25
26 noSuchMethod(i) => "noSuchMethod"; // Should never be called in this test.
27 }
28
29 // Class with only final field has setter in implicit interface.
30 class A {
31 final int x = 42;
32 }
33
34 // Should get warning because the implicit interface contains the setter,
35 // and this non-abstract class doesn't.
36 class AI
37 implements A /// 01: static type warning
38 {
39 int get x => 37;
40 }
41
42 // Erases static type information. Used to avoid *static* warnings when
43 // using a setter for a final field.
44 erase(x) => x;
45
46 void main() {
47 Expect.equals(42, new C().x);
48 Expect.throws(() { erase(new C()).x = 10; });
49 Expect.equals(42, new C().cx);
50 Expect.throws(() { erase(new C()).cx = 10; });
51 Expect.equals(37, new C().bx);
52 Expect.equals(10, (erase(new C())..bx = 10).bx);
53
54 Expect.equals(42, new A().x);
55 Expect.throws(() { erase(new A()).x = 10; });
56 Expect.equals(37, new AI().x);
57 Expect.throws(() { erase(new AI()).x = 10; });
58
59 Expect.equals("toplevel", x); // Should not have changed.
60 }
OLDNEW
« 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