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

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

Issue 1094903002: Better hints for await in non-async functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 'dart:async'; 6 import 'dart:async';
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import "package:compiler/src/resolution/resolution.dart"; 10 import "package:compiler/src/resolution/resolution.dart";
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 testSwitch, 83 testSwitch,
84 testTypeVariables, 84 testTypeVariables,
85 testToString, 85 testToString,
86 testIndexedOperator, 86 testIndexedOperator,
87 testIncrementsAndDecrements, 87 testIncrementsAndDecrements,
88 testOverrideHashCodeCheck, 88 testOverrideHashCodeCheck,
89 testSupertypeOrder, 89 testSupertypeOrder,
90 testConstConstructorAndNonFinalFields, 90 testConstConstructorAndNonFinalFields,
91 testCantAssignMethods, 91 testCantAssignMethods,
92 testCantAssignFinalAndConsts, 92 testCantAssignFinalAndConsts,
93 testAwaitHint,
93 ], (f) => f())); 94 ], (f) => f()));
94 } 95 }
95 96
96 Future testSupertypeOrder() { 97 Future testSupertypeOrder() {
97 return Future.wait([ 98 return Future.wait([
98 MockCompiler.create((MockCompiler compiler) { 99 MockCompiler.create((MockCompiler compiler) {
99 compiler.parseScript(""" 100 compiler.parseScript("""
100 class I1 {} 101 class I1 {}
101 class I2 {} 102 class I2 {}
102 class J1 extends K1 {} 103 class J1 extends K1 {}
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 main() => new B().m(); 1264 main() => new B().m();
1264 class A { 1265 class A {
1265 int x = 1; 1266 int x = 1;
1266 } 1267 }
1267 class B extends A { 1268 class B extends A {
1268 m() { super.x = 2; } 1269 m() { super.x = 2; }
1269 } 1270 }
1270 ''', []); 1271 ''', []);
1271 } 1272 }
1272 1273
1273
1274 /// Helper to test that [script] produces all the given [warnings]. 1274 /// Helper to test that [script] produces all the given [warnings].
1275 checkWarningOn(String script, List<MessageKind> warnings) { 1275 checkWarningOn(String script, List<MessageKind> warnings) {
1276 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2); 1276 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2);
1277 asyncTest(() => compileScript(script).then((compiler) { 1277 asyncTest(() => compileScript(script).then((compiler) {
1278 Expect.equals(0, compiler.errors.length); 1278 Expect.equals(0, compiler.errors.length);
1279 Expect.equals(warnings.length, compiler.warnings.length); 1279 Expect.equals(warnings.length, compiler.warnings.length);
1280 for (int i = 0; i < warnings.length; i++) { 1280 for (int i = 0; i < warnings.length; i++) {
1281 Expect.equals(warnings[i], compiler.warnings[i].message.kind); 1281 Expect.equals(warnings[i], compiler.warnings[i].message.kind);
1282 } 1282 }
1283 })); 1283 }));
1284 } 1284 }
1285
1286 testAwaitHint() {
1287 check(String script, {String className, String functionName}) {
1288 var prefix = className == null
1289 ? "Cannot resolve 'await'"
1290 : "No member named 'await' in class '$className'";
1291 var where = functionName == null
1292 ? 'the enclosing function' : "'$functionName'";
1293 asyncTest(() => compileScript(script).then((compiler) {
1294 Expect.equals(0, compiler.errors.length);
1295 Expect.equals(1, compiler.warnings.length);
1296 Expect.equals("$prefix.\n"
1297 "Did you mean to add the 'async' marker to $where?",
1298 '${compiler.warnings[0].message}');
1299 }));
1300 }
1301 check('main() { await -3; }', functionName: 'main');
1302 check('main() { () => await -3; }');
1303 check('foo() => await -3; main() => foo();', functionName: 'foo');
1304 check('''
1305 class A {
1306 m() => await - 3;
1307 }
1308 main() => new A().m();
1309 ''', className: 'A', functionName: 'm');
1310 check('''
1311 class A {
1312 static m() => await - 3;
1313 }
1314 main() => A.m();
1315 ''', functionName: 'm');
1316 check('''
1317 class A {
1318 m() => () => await - 3;
1319 }
1320 main() => new A().m();
1321 ''', className: 'A');
1322 }
OLDNEW
« pkg/compiler/lib/src/resolution/members.dart ('K') | « pkg/compiler/lib/src/warnings.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698