Chromium Code Reviews| Index: dart/tests/language/fauxverride_test.dart |
| diff --git a/dart/tests/language/fauxverride_test.dart b/dart/tests/language/fauxverride_test.dart |
| index 4e7b7cc4c5f467f46b22d86ce9bf11f0b0715701..a136830b60407d727c11b5251d24738c1789b08d 100644 |
| --- a/dart/tests/language/fauxverride_test.dart |
| +++ b/dart/tests/language/fauxverride_test.dart |
| @@ -2,35 +2,93 @@ |
| // 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. |
| -// Test that static members cannot be overridden (static type warning only). |
| +// Test the semantics of static members mixed with instance members. |
| -m() {} |
| +// Following are relevant quotes from Dart Programming Language |
| +// Specification, Draft Version 0.10, June 7, 2012. |
| + |
| +// 7 Classes: |
| + |
| +// "It is a compile-time error if a class has an instance method and a |
| +// static member method with the same name." |
| + |
| +// 7.1 Instance Methods: |
| + |
| +// "Instance methods are functions (6) whose declarations are |
| +// immediately contained within a class declaration and that are not |
| +// declared static. The instance methods of a class C are those |
| +// instance methods declared by C and the instance methods inherited |
| +// by C from its superclass." |
| + |
| + |
| +// 7.6 Static Methods |
| + |
| +// "Static methods are functions whose declarations are immediately |
| +// contained within a class declaration and that are declared |
| +// static. The static methods of a class C are those static methods |
| +// declared by C." |
| + |
| +// 7.7 Static Variables |
| + |
| +// "Static variables are variables whose declarations are immediately |
| +// contained within a class declaration and that are declared |
| +// static. The static variables of a class C are those static |
| +// variables declared by C." |
| + |
| +// "A static variable declaration of one of the forms static T v;, |
| +// static T v = e; , static const T v = e; or static final T v = e; |
| +// always induces an implicit static getter function (7.2) with |
| +// signature static T get v() whose invocation evaluates as described |
| +// below (7.7.1)." |
| + |
| +m() => 'top level'; |
| class Super { |
| - Super() {} |
| // No error from hiding. |
| - static m() {} |
| + static m() => 'super'; |
| + |
| + static var i = 'super'; |
| - static var i; |
| + instanceMethod() => m(); |
| - instanceMethod() {} |
| + instanceMethod2() => m(); |
| } |
| class Sub extends Super { |
| - Sub() : super(); |
| - static m() {} /// 01: static type warning |
| + // According to 7.6, static methods are not inherited. |
| + static m() => 'sub'; |
| - static var i; /// 02: static type warning |
| + // According to 7.7, static variables are not inherited. |
| + static var i = 'sub'; |
| - static instanceMethod() {} /// 03: compile-time error |
| + // According to 7.1, instance methods include those of the |
| + // superclass, and according to 7, it is a compile-time to have an |
| + // instance method and static method with the same name. |
| + static /// 03: compile-time error |
| + instanceMethod() => m(); |
| - static i() {} /// 04: static type warning |
| + // According to 7.7, static variables are not inherited. |
| + static i() => m(); |
|
kasperl
2012/06/20 08:58:32
So you can have a static method called i and a sta
ahe
2012/06/20 09:04:40
No. Static members are not inherited.
zundel
2012/06/20 09:08:57
Its the lesser of evils maybe. Unqualified access
ahe
2012/06/20 11:00:18
Actually, after removing the "compile-time error"
|
| - static var instanceMethod; /// 05: compile-time error |
| + // According to 7.1, instance methods include those of the |
| + // superclass, and according to 7, it is a compile-time to have an |
| + // instance method and static method with the same |
| + // name. Furthermore, according to 7.7 a static variable induces an |
| + // implicit getter function (a static method). |
| + static var instanceMethod2; /// 05: compile-time error |
| - foo() {} |
| + foo() => 'foo'; |
| } |
| main() { |
| - new Sub().foo(); |
| + Expect.equals('foo', new Sub().foo()); |
| + Expect.equals('top level', m()); |
| + Expect.equals('super', Super.m()); |
| + Expect.equals('sub', Sub.m()); |
| + Expect.equals('super', Super.i); |
| + Expect.equals('sub', Sub.i()); |
| + Expect.equals('super', new Super().instanceMethod()); |
| + Expect.equals('sub', new Sub().instanceMethod()); |
| + Expect.equals('super', new Super().instanceMethod2()); |
| + Expect.equals('super', new Sub().instanceMethod2()); |
| } |