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

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

Issue 24268002: Fix bug in the closure methods, where iterating over the boxed variable did not return the variable… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import "package:async_helper/async_helper.dart"; 6 import "package:async_helper/async_helper.dart";
7 import 'compiler_helper.dart'; 7 import 'compiler_helper.dart';
8 import 'parser_helper.dart' show buildSourceString; 8 import 'parser_helper.dart' show buildSourceString;
9 9
10 const String TEST = """ 10 const String TEST = """
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 var b = {}; 76 var b = {};
77 b = 42; 77 b = 42;
78 return b; 78 return b;
79 } 79 }
80 a = g(); 80 a = g();
81 } finally { 81 } finally {
82 } 82 }
83 return a; 83 return a;
84 } 84 }
85 85
86 returnIntOrNull() {
87 for (var b in [42]) {
88 var bar = 42;
89 f() => bar;
90 bar = null;
91 return f();
92 }
93 return 42;
94 }
95
86 class A { 96 class A {
87 foo() { 97 foo() {
88 f() => this; 98 f() => this;
89 return f(); 99 return f();
90 } 100 }
91 } 101 }
92 102
93 main() { 103 main() {
94 returnInt1(); 104 returnInt1();
95 returnDyn1(); 105 returnDyn1();
96 returnInt2(); 106 returnInt2();
97 returnDyn2(); 107 returnDyn2();
98 returnInt3(); 108 returnInt3();
99 returnDyn3(); 109 returnDyn3();
100 returnInt4(); 110 returnInt4();
101 returnNum1(); 111 returnNum1();
112 returnIntOrNull();
102 new A().foo(); 113 new A().foo();
103 } 114 }
104 """; 115 """;
105 116
106 117
107 void main() { 118 void main() {
108 Uri uri = new Uri(scheme: 'source'); 119 Uri uri = new Uri(scheme: 'source');
109 var compiler = compilerFor(TEST, uri); 120 var compiler = compilerFor(TEST, uri);
110 asyncTest(() => compiler.runCompiler(uri).then((_) { 121 asyncTest(() => compiler.runCompiler(uri).then((_) {
111 var typesInferrer = compiler.typesTask.typesInferrer; 122 var typesInferrer = compiler.typesTask.typesInferrer;
112 123
113 checkReturn(String name, type) { 124 checkReturn(String name, type) {
114 var element = findElement(compiler, name); 125 var element = findElement(compiler, name);
115 Expect.equals(type, 126 Expect.equals(type,
116 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); 127 typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
117 } 128 }
118 129
119 checkReturn('returnInt1', compiler.typesTask.intType); 130 checkReturn('returnInt1', compiler.typesTask.intType);
120 checkReturn('returnInt2', compiler.typesTask.intType); 131 checkReturn('returnInt2', compiler.typesTask.intType);
121 checkReturn('returnInt3', compiler.typesTask.intType); 132 checkReturn('returnInt3', compiler.typesTask.intType);
122 checkReturn('returnInt4', compiler.typesTask.intType); 133 checkReturn('returnInt4', compiler.typesTask.intType);
134 checkReturn('returnIntOrNull', compiler.typesTask.intType.nullable());
123 135
124 checkReturn('returnDyn1', compiler.typesTask.dynamicType.nonNullable()); 136 checkReturn('returnDyn1', compiler.typesTask.dynamicType.nonNullable());
125 checkReturn('returnDyn2', compiler.typesTask.dynamicType.nonNullable()); 137 checkReturn('returnDyn2', compiler.typesTask.dynamicType.nonNullable());
126 checkReturn('returnDyn3', compiler.typesTask.dynamicType.nonNullable()); 138 checkReturn('returnDyn3', compiler.typesTask.dynamicType.nonNullable());
127 checkReturn('returnNum1', compiler.typesTask.numType); 139 checkReturn('returnNum1', compiler.typesTask.numType);
128 140
129 checkReturnInClass(String className, String methodName, type) { 141 checkReturnInClass(String className, String methodName, type) {
130 var cls = findElement(compiler, className); 142 var cls = findElement(compiler, className);
131 var element = cls.lookupLocalMember(buildSourceString(methodName)); 143 var element = cls.lookupLocalMember(buildSourceString(methodName));
132 Expect.equals(type, 144 Expect.equals(type,
133 typesInferrer.getReturnTypeOfElement(element).simplify(compiler)); 145 typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
134 } 146 }
135 var cls = findElement(compiler, 'A'); 147 var cls = findElement(compiler, 'A');
136 checkReturnInClass('A', 'foo', new TypeMask.nonNullExact(cls.rawType)); 148 checkReturnInClass('A', 'foo', new TypeMask.nonNullExact(cls.rawType));
137 })); 149 }));
138 } 150 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698