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

Unified Diff: tests/language/src/GettersSetters2Test.dart

Issue 9315061: Specify the types for Element.classes, Element.elements and Node.nodes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed dynamic type error issue with VM. Created 8 years, 9 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 | « compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/src/GettersSetters2Test.dart
diff --git a/tests/language/src/GettersSetters2Test.dart b/tests/language/src/GettersSetters2Test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..950630a829951bf287e8858e2cbdfa0c5d64eeb6
--- /dev/null
+++ b/tests/language/src/GettersSetters2Test.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, 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.
+
+// Tests classes with getters and setters that do not have the same type.
+
+class A {
+ int a() { return 37;}
+}
+
+class B extends A{
+ int b() { return 38; }
+}
+
+class C {}
+
+class T1 {
+ A getterField;
+ A get field() { return getterField; }
+ // OK, B is assignable to A
+ void set field(B arg) { getterField = arg; }
+}
+
+class T2 {
+ A getterField;
+ C setterField;
+ A get field() { return getterField; }
+
+ // Type C is not assignable to A
+ void set field(C arg) { setterField = arg; } /// 01: static type error
+}
+
+class T3 {
+ B getterField;
+ B get field() { return getterField; }
+ // OK, A is assignable to B
+ void set field(A arg) { getterField = arg; }
+}
+
+
+main() {
+ T1 instance1 = new T1();
+ T2 instance2 = new T2(); /// 01: continued
+ T3 instance3 = new T3();
+
+ instance1.field = new B();
+ A resultA = instance1.field;
+ instance1.field = new A(); /// 03: dynamic type error
+ B resultB = instance1.field;
+
+ int result;
+ result = instance1.field.a();
+ Expect.equals(37, result);
+
+ // Type 'A' has no method named 'b'
+ instance1.field.b(); /// 02: static type error
+
+ instance3.field = new B();
+ result = instance3.field.a();
+ Expect.equals(37, result);
+ result = instance3.field.b();
+ Expect.equals(38, result);
+}
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698