| 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 an attempt to invoke a prefix is handled consistently with the |
| 6 // following spec text from section 16.14.3 (Unqualified invocation): |
| 7 // An unqualifiedfunction invocation i has the form |
| 8 // id(a1, ..., an, xn+1 : an+1, ..., xn+k : an+k), |
| 9 // where id is an identifier. |
| 10 // If there exists a lexically visible declaration named id, let fid be the |
| 11 // innermost such declaration. Then |
| 12 // - If fid isa local function, a library function, a library or static |
| 13 // getter or a variable then ... |
| 14 // - Otherwise, if fid is a static method of the enclosing class C, ... |
| 15 // - Otherwise, fid is considered equivalent to the ordinary method |
| 16 // invocation this.id(a1, ..., an, xn+1 : an+1, ..., xn+k : an+k). |
| 17 // |
| 18 // Therefore, if p is an import prefix, evaluation of "p()" should be |
| 19 // equivalent to "this.p()". That is, it should call the method "p" |
| 20 // dynamically if inside a method, and should produce a NoSucMethodError (and a |
| 21 // static warning) outside a method. |
| 22 |
| 23 import "package:expect/expect.dart"; |
| 24 import "empty_library.dart" as p; |
| 25 |
| 26 class Base { |
| 27 var pCalled = false; |
| 28 |
| 29 void p() { |
| 30 pCalled = true; |
| 31 } |
| 32 } |
| 33 |
| 34 class Derived extends Base { |
| 35 void f() { |
| 36 p(); Expect.isTrue(pCalled); /// 01: ok |
| 37 } |
| 38 } |
| 39 |
| 40 noMethod(e) => e is NoSuchMethodError; |
| 41 |
| 42 main() { |
| 43 new Derived().f(); |
| 44 Expect.throws(() { p(); }, noMethod); /// 02: static type warning |
| 45 } |
| OLD | NEW |