| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 // Validate that assignment to a prefix is handled consistently with the |
| 6 // following spec text from section 16.19 (Assignment): |
| 7 // Evaluation of an assignment a of the form v = e proceeds as follows: |
| 8 // Let d be the innermost declaration whose name is v or v=, if it exists. |
| 9 // If d is the declaration of a local variable, ... |
| 10 // If d is the declaration of a library variable, ... |
| 11 // Otherwise, if d is the declaration of a static variable, ... |
| 12 // Otherwise, if a ocurs inside a top level or static function (be it |
| 13 // function, method, getter, or setter) or variable initializer, evaluation |
| 14 // of a causes e to be evaluated, after which a NoSuchMethodError is thrown. |
| 15 // Otherwise, the assignment is equivalent to the assignment this.v = e. |
| 16 // |
| 17 // Therefore, if p is an import prefix, evaluation of "p = ..." should be |
| 18 // equivalent to "this.p = ..." inside a method, and should produce a |
| 19 // NoSuchMethodError outside a method. |
| 20 |
| 21 import "package:expect/expect.dart"; |
| 22 import "empty_library.dart" as p; |
| 23 |
| 24 class Base { |
| 25 var p; |
| 26 } |
| 27 |
| 28 class Derived extends Base { |
| 29 void f() { |
| 30 p = 1; Expect.equals(1, this.p); /// 01: ok |
| 31 } |
| 32 } |
| 33 |
| 34 bool gCalled = false; |
| 35 |
| 36 g() { |
| 37 gCalled = true; |
| 38 return 1; |
| 39 } |
| 40 |
| 41 noMethod(e) => e is NoSuchMethodError; |
| 42 |
| 43 main() { |
| 44 new Derived().f(); |
| 45 Expect.throws(() { p = g(); }, noMethod); Expect.isTrue(gCalled); /// 02: stat
ic type warning |
| 46 } |
| OLD | NEW |