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

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

Issue 1750143005: Move more messages. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Undo change to analyze_test_test.dart Created 4 years, 9 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
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 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/constants/expressions.dart'; 10 import 'package:compiler/src/constants/expressions.dart';
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 }), 851 }),
852 852
853 MockCompiler.create((MockCompiler compiler) { 853 MockCompiler.create((MockCompiler compiler) {
854 compiler.parseScript("""enum Enum { A } 854 compiler.parseScript("""enum Enum { A }
855 main() { Enum e = Enum.B; }"""); 855 main() { Enum e = Enum.B; }""");
856 FunctionElement mainElement = compiler.mainApp.find(MAIN); 856 FunctionElement mainElement = compiler.mainApp.find(MAIN);
857 compiler.resolver.resolve(mainElement); 857 compiler.resolver.resolve(mainElement);
858 DiagnosticCollector collector = compiler.diagnosticCollector; 858 DiagnosticCollector collector = compiler.diagnosticCollector;
859 Expect.equals(1, collector.warnings.length, 859 Expect.equals(1, collector.warnings.length,
860 'Unexpected warnings: ${collector.warnings}'); 860 'Unexpected warnings: ${collector.warnings}');
861 Expect.equals(MessageKind.MEMBER_NOT_FOUND, 861 Expect.equals(MessageKind.UNDEFINED_GETTER,
862 collector.warnings.first.message.kind); 862 collector.warnings.first.message.kind);
863 Expect.equals(0, collector.errors.length, 863 Expect.equals(0, collector.errors.length,
864 'Unexpected errors: ${collector.errors}'); 864 'Unexpected errors: ${collector.errors}');
865 }), 865 }),
866 866
867 MockCompiler.create((MockCompiler compiler) { 867 MockCompiler.create((MockCompiler compiler) {
868 compiler.parseScript("""enum Enum { A } 868 compiler.parseScript("""enum Enum { A }
869 main() { List values = Enum.values; }"""); 869 main() { List values = Enum.values; }""");
870 FunctionElement mainElement = compiler.mainApp.find(MAIN); 870 FunctionElement mainElement = compiler.mainApp.find(MAIN);
871 compiler.resolver.resolve(mainElement); 871 compiler.resolver.resolve(mainElement);
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 1258
1259 // Can't override instance methods 1259 // Can't override instance methods
1260 checkWarningOn(''' 1260 checkWarningOn('''
1261 main() { new B().bar(); } 1261 main() { new B().bar(); }
1262 class B { 1262 class B {
1263 mname() {} 1263 mname() {}
1264 bar() { 1264 bar() {
1265 mname = () => null; 1265 mname = () => null;
1266 } 1266 }
1267 } 1267 }
1268 ''', [MessageKind.SETTER_NOT_FOUND]); 1268 ''', [MessageKind.UNDEFINED_SETTER]);
1269 checkWarningOn(''' 1269 checkWarningOn('''
1270 main() { new B().bar(); } 1270 main() { new B().bar(); }
1271 class B { 1271 class B {
1272 mname() {} 1272 mname() {}
1273 bar() { 1273 bar() {
1274 this.mname = () => null; 1274 this.mname = () => null;
1275 } 1275 }
1276 } 1276 }
1277 ''', [MessageKind.SETTER_NOT_FOUND]); 1277 ''', [MessageKind.UNDEFINED_SETTER]);
1278 1278
1279 // Can't override super methods 1279 // Can't override super methods
1280 checkWarningOn(''' 1280 checkWarningOn('''
1281 main() { new B().bar(); } 1281 main() { new B().bar(); }
1282 class A { 1282 class A {
1283 mname() {} 1283 mname() {}
1284 } 1284 }
1285 class B extends A { 1285 class B extends A {
1286 bar() { 1286 bar() {
1287 super.mname = () => 6; 1287 super.mname = () => 6;
1288 } 1288 }
1289 } 1289 }
1290 ''', [MessageKind.ASSIGNING_METHOD_IN_SUPER, 1290 ''', [MessageKind.ASSIGNING_METHOD_IN_SUPER,
1291 // TODO(johnniwinther): Avoid duplicate warnings. 1291 // TODO(johnniwinther): Avoid duplicate warnings.
1292 MessageKind.SETTER_NOT_FOUND]); 1292 MessageKind.UNDEFINED_SETTER]);
1293 1293
1294 // But index operators should be OK 1294 // But index operators should be OK
1295 checkWarningOn(''' 1295 checkWarningOn('''
1296 main() { new B().bar(); } 1296 main() { new B().bar(); }
1297 class B { 1297 class B {
1298 operator[]=(x, y) {} 1298 operator[]=(x, y) {}
1299 bar() { 1299 bar() {
1300 this[1] = 3; // This is OK 1300 this[1] = 3; // This is OK
1301 } 1301 }
1302 } 1302 }
(...skipping 11 matching lines...) Expand all
1314 ''', []); 1314 ''', []);
1315 } 1315 }
1316 1316
1317 testCantAssignFinalAndConsts() { 1317 testCantAssignFinalAndConsts() {
1318 // Can't write final or const locals. 1318 // Can't write final or const locals.
1319 checkWarningOn(''' 1319 checkWarningOn('''
1320 main() { 1320 main() {
1321 final x = 1; 1321 final x = 1;
1322 x = 2; 1322 x = 2;
1323 } 1323 }
1324 ''', [MessageKind.CANNOT_RESOLVE_SETTER]); 1324 ''', [MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER]);
1325 checkWarningOn(''' 1325 checkWarningOn('''
1326 main() { 1326 main() {
1327 const x = 1; 1327 const x = 1;
1328 x = 2; 1328 x = 2;
1329 } 1329 }
1330 ''', [MessageKind.CANNOT_RESOLVE_SETTER]); 1330 ''', [MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER]);
1331 checkWarningOn(''' 1331 checkWarningOn('''
1332 final x = 1; 1332 final x = 1;
1333 main() { x = 3; } 1333 main() { x = 3; }
1334 ''', [MessageKind.CANNOT_RESOLVE_SETTER]); 1334 ''', [MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER]);
1335 1335
1336 checkWarningOn(''' 1336 checkWarningOn('''
1337 const x = 1; 1337 const x = 1;
1338 main() { x = 3; } 1338 main() { x = 3; }
1339 ''', [MessageKind.CANNOT_RESOLVE_SETTER]); 1339 ''', [MessageKind.UNDEFINED_STATIC_SETTER_BUT_GETTER]);
1340 1340
1341 // Detect assignments to final fields: 1341 // Detect assignments to final fields:
1342 checkWarningOn(''' 1342 checkWarningOn('''
1343 main() => new B().m(); 1343 main() => new B().m();
1344 class B { 1344 class B {
1345 final x = 1; 1345 final x = 1;
1346 m() { x = 2; } 1346 m() { x = 2; }
1347 } 1347 }
1348 ''', [MessageKind.SETTER_NOT_FOUND]); 1348 ''', [MessageKind.UNDEFINED_SETTER]);
1349 1349
1350 // ... even if 'this' is explicit: 1350 // ... even if 'this' is explicit:
1351 checkWarningOn(''' 1351 checkWarningOn('''
1352 main() => new B().m(); 1352 main() => new B().m();
1353 class B { 1353 class B {
1354 final x = 1; 1354 final x = 1;
1355 m() { this.x = 2; } 1355 m() { this.x = 2; }
1356 } 1356 }
1357 ''', [MessageKind.SETTER_NOT_FOUND]); 1357 ''', [MessageKind.UNDEFINED_SETTER]);
1358 1358
1359 // ... and in super class: 1359 // ... and in super class:
1360 checkWarningOn(''' 1360 checkWarningOn('''
1361 main() => new B().m(); 1361 main() => new B().m();
1362 class A { 1362 class A {
1363 final x = 1; 1363 final x = 1;
1364 } 1364 }
1365 class B extends A { 1365 class B extends A {
1366 m() { super.x = 2; } 1366 m() { super.x = 2; }
1367 } 1367 }
1368 ''', [MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER, 1368 ''', [MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER,
1369 // TODO(johnniwinther): Avoid duplicate warnings. 1369 // TODO(johnniwinther): Avoid duplicate warnings.
1370 MessageKind.SETTER_NOT_FOUND]); 1370 MessageKind.UNDEFINED_SETTER]);
1371 1371
1372 // But non-final fields are OK: 1372 // But non-final fields are OK:
1373 checkWarningOn(''' 1373 checkWarningOn('''
1374 main() => new B().m(); 1374 main() => new B().m();
1375 class A { 1375 class A {
1376 int x = 1; 1376 int x = 1;
1377 } 1377 }
1378 class B extends A { 1378 class B extends A {
1379 m() { super.x = 2; } 1379 m() { super.x = 2; }
1380 } 1380 }
1381 ''', []); 1381 ''', []);
1382 1382
1383 // Check getter without setter. 1383 // Check getter without setter.
1384 checkWarningOn(''' 1384 checkWarningOn('''
1385 main() => new B().m(); 1385 main() => new B().m();
1386 class A { 1386 class A {
1387 get x => 1; 1387 get x => 1;
1388 } 1388 }
1389 class B extends A { 1389 class B extends A {
1390 m() { super.x = 2; } 1390 m() { super.x = 2; }
1391 } 1391 }
1392 ''', [MessageKind.SETTER_NOT_FOUND_IN_SUPER, 1392 ''', [MessageKind.UNDEFINED_SUPER_SETTER,
1393 // TODO(johnniwinther): Avoid duplicate warnings. 1393 // TODO(johnniwinther): Avoid duplicate warnings.
1394 MessageKind.SETTER_NOT_FOUND]); 1394 MessageKind.UNDEFINED_SETTER]);
1395 } 1395 }
1396 1396
1397 /// Helper to test that [script] produces all the given [warnings]. 1397 /// Helper to test that [script] produces all the given [warnings].
1398 checkWarningOn(String script, List<MessageKind> warnings) { 1398 checkWarningOn(String script, List<MessageKind> warnings) {
1399 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2); 1399 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2);
1400 asyncTest(() => compileScript(script).then((compiler) { 1400 asyncTest(() => compileScript(script).then((compiler) {
1401 DiagnosticCollector collector = compiler.diagnosticCollector; 1401 DiagnosticCollector collector = compiler.diagnosticCollector;
1402 Expect.equals(0, collector.errors.length, 1402 Expect.equals(0, collector.errors.length,
1403 'Unexpected errors in\n$script\n${collector.errors}'); 1403 'Unexpected errors in\n$script\n${collector.errors}');
1404 Expect.equals(warnings.length, collector.warnings.length, 1404 Expect.equals(warnings.length, collector.warnings.length,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1441 }
1442 main() => A.m(); 1442 main() => A.m();
1443 ''', functionName: 'm'); 1443 ''', functionName: 'm');
1444 check(''' 1444 check('''
1445 class A { 1445 class A {
1446 m() => () => await - 3; 1446 m() => () => await - 3;
1447 } 1447 }
1448 main() => new A().m(); 1448 main() => new A().m();
1449 ''', className: 'A'); 1449 ''', className: 'A');
1450 } 1450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698