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

Side by Side Diff: tests/language/methods_as_constants_test.dart

Issue 10872059: Static and top-level methods can be compile time constants. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
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 topLevelMethod() => 't';
6
7 const topLevelFieldForTopLevelMethod = topLevelMethod;
8 const topLevelFieldForStaticMethod = A.staticMethod;
9
10 class A {
11 final Function closure;
12 const A(this.closure);
13 const A.defaultTopLevel([this.closure = topLevelMethod]);
14 const A.defaultStatic([this.closure = staticMethod]);
15 const A.defaultStatic2([this.closure = A.staticMethod]);
16 run() => closure();
17
18 static staticMethod() => 's';
19 static const staticFieldForStaticMethod = staticMethod;
20 static const staticFieldForTopLevelMethod = topLevelMethod;
21 }
22
23 main() {
24 Expect.equals('t', (const A(topLevelMethod)).run());
25 Expect.equals('s', (const A(A.staticMethod)).run());
26 Expect.equals('t', (const A.defaultTopLevel()).run());
27 Expect.equals('s', (const A.defaultStatic()).run());
28 Expect.equals('s', (const A.defaultStatic2()).run());
29 Expect.equals('t', (new A.defaultTopLevel()).run());
30 Expect.equals('s', (new A.defaultStatic()).run());
31 Expect.equals('s', (new A.defaultStatic2()).run());
32 Expect.equals('t', topLevelFieldForTopLevelMethod());
33 Expect.equals('s', topLevelFieldForStaticMethod());
34 Expect.equals('t', A.staticFieldForTopLevelMethod());
35 Expect.equals('s', A.staticFieldForStaticMethod());
36
37 var map = const {'t': topLevelMethod, 's': A.staticMethod };
38 Expect.equals('t', map['t']());
39 Expect.equals('s', map['s']());
40 }
OLDNEW
« lib/compiler/implementation/compile_time_constants.dart ('K') | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698