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

Side by Side Diff: tests/compiler/dart2js/simple_inferrer_no_such_method_test.dart

Issue 14049010: Take noSuchMethod into account when computing the potential targets of a call. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/language/no_such_method3_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import 'package:expect/expect.dart';
6
7 import 'compiler_helper.dart';
8 import 'parser_helper.dart';
9
10 const String TEST1 = """
11 class A {
12 noSuchMethod(im) => 42;
13 }
14
15 class B extends A {
16 foo();
17 }
18
19 class C extends B {
20 foo() => {};
21 }
22
23 var a;
24 test1() => new A().foo();
25 test2() => a.foo();
26 test3() => new B().foo();
27 test4() => new C().foo();
28 test5() => (a ? new A() : new B()).foo();
29 test6() => (a ? new B() : new C()).foo();
30
31 main() {
32 test1();
33 test2();
34 test3();
35 test4();
36 test5();
37 test6();
38 }
39 """;
40
41 const String TEST2 = """
42 abstract class A {
43 noSuchMethod(im) => 42;
44 }
45
46 class B extends A {
47 foo() => {};
48 }
49
50 class C extends B {
51 foo() => {};
52 }
53
54 class D implements A {
55 foo() => {};
56 noSuchMethod(im) => 42.5;
57 }
58
59 var a;
60 test1() => a.foo();
61 test2() => new B().foo();
62 test3() => new C().foo();
63 test4() => (a ? new B() : new C()).foo();
64 test5() => (a ? new B() : new D()).foo();
65
66 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod.
67 test6() => a.bar();
68
69 // Can hit A.noSuchMethod.
70 test7() => new B().bar();
71 test8() => new C().bar();
72 test9() => (a ? new B() : new C()).bar();
73
74 // Can hit A.noSuchMethod, D.noSuchMethod and Object.noSuchMethod.
75 test10() => (a ? new B() : new D()).bar();
76
77 // Can hit D.noSuchMethod.
78 test11() => new D().bar();
79
80 main() {
81 test1();
82 test2();
83 test3();
84 test4();
85 test5();
86 test6();
87 test7();
88 test8();
89 test9();
90 test10();
91 test11();
92 }
93 """;
94
95 main() {
96 Uri uri = new Uri.fromComponents(scheme: 'source');
97
98 var compiler = compilerFor(TEST1, uri);
99 compiler.runCompiler(uri);
100 var typesInferrer = compiler.typesTask.typesInferrer;
101
102 checkReturn(String name, type) {
103 var element = findElement(compiler, name);
104 Expect.equals(type, typesInferrer.returnTypeOf[element], name);
105 }
106
107 checkReturn('test1', typesInferrer.intType);
108 checkReturn('test2', typesInferrer.dynamicType);
109 checkReturn('test3', typesInferrer.intType);
110 checkReturn('test4', typesInferrer.mapType);
111 checkReturn('test5', typesInferrer.dynamicType);
112 checkReturn('test6', typesInferrer.dynamicType);
113
114 compiler = compilerFor(TEST2, uri);
115 compiler.runCompiler(uri);
116 typesInferrer = compiler.typesTask.typesInferrer;
117
118 checkReturn('test1', typesInferrer.dynamicType);
119 checkReturn('test2', typesInferrer.mapType);
120 checkReturn('test3', typesInferrer.mapType);
121 checkReturn('test4', typesInferrer.mapType);
122 checkReturn('test5', typesInferrer.mapType);
123
124 // TODO(ngeoffray): The reason for nullablity is because the
125 // inferrer thinks Object.noSuchMethod return null. Once we track
126 // aborting control flow in the analysis, we won't get the nullable
127 // anymore.
128 checkReturn('test6', typesInferrer.numType.nullable());
129 checkReturn('test7', typesInferrer.intType);
130 checkReturn('test8', typesInferrer.intType);
131 checkReturn('test9', typesInferrer.intType);
132 checkReturn('test10', typesInferrer.numType.nullable());
133 checkReturn('test11', typesInferrer.doubleType);
134 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/language/no_such_method3_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698