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

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

Issue 1090923004: Make super.foo= erroneous if they are not assignable. (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
« no previous file with comments | « pkg/compiler/lib/src/warnings.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) 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 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 // Can't override instance methods 1170 // Can't override instance methods
1171 checkWarningOn(''' 1171 checkWarningOn('''
1172 main() { new B().bar(); } 1172 main() { new B().bar(); }
1173 class B { 1173 class B {
1174 mname() {} 1174 mname() {}
1175 bar() { 1175 bar() {
1176 mname = () => null; 1176 mname = () => null;
1177 } 1177 }
1178 } 1178 }
1179 ''', [MessageKind.SETTER_NOT_FOUND]); 1179 ''', [MessageKind.SETTER_NOT_FOUND]);
1180 checkWarningOn('''
1181 main() { new B().bar(); }
1182 class B {
1183 mname() {}
1184 bar() {
1185 this.mname = () => null;
1186 }
1187 }
1188 ''', [MessageKind.SETTER_NOT_FOUND]);
1180 1189
1181 // Can't override super methods 1190 // Can't override super methods
1182 checkWarningOn(''' 1191 checkWarningOn('''
1183 main() { new B().bar(); } 1192 main() { new B().bar(); }
1184 class A { 1193 class A {
1185 mname() {} 1194 mname() {}
1186 } 1195 }
1187 class B extends A { 1196 class B extends A {
1188 bar() { 1197 bar() {
1189 super.mname = () => 6; 1198 super.mname = () => 6;
1190 } 1199 }
1191 } 1200 }
1192 ''', [MessageKind.SETTER_NOT_FOUND]); 1201 ''', [MessageKind.ASSIGNING_METHOD_IN_SUPER]);
1193 1202
1194 // But index operators should be OK 1203 // But index operators should be OK
1195 checkWarningOn(''' 1204 checkWarningOn('''
1196 main() { new B().bar(); } 1205 main() { new B().bar(); }
1197 class B { 1206 class B {
1198 operator[]=(x, y) {} 1207 operator[]=(x, y) {}
1199 bar() { 1208 bar() {
1200 this[1] = 3; // This is OK 1209 this[1] = 3; // This is OK
1201 } 1210 }
1202 } 1211 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 1249
1241 // Detect assignments to final fields: 1250 // Detect assignments to final fields:
1242 checkWarningOn(''' 1251 checkWarningOn('''
1243 main() => new B().m(); 1252 main() => new B().m();
1244 class B { 1253 class B {
1245 final x = 1; 1254 final x = 1;
1246 m() { x = 2; } 1255 m() { x = 2; }
1247 } 1256 }
1248 ''', [MessageKind.SETTER_NOT_FOUND]); 1257 ''', [MessageKind.SETTER_NOT_FOUND]);
1249 1258
1259 // ... even if 'this' is explicit:
1260 checkWarningOn('''
1261 main() => new B().m();
1262 class B {
1263 final x = 1;
1264 m() { this.x = 2; }
1265 }
1266 ''', [MessageKind.SETTER_NOT_FOUND]);
1267
1250 // ... and in super class: 1268 // ... and in super class:
1251 checkWarningOn(''' 1269 checkWarningOn('''
1252 main() => new B().m(); 1270 main() => new B().m();
1253 class A { 1271 class A {
1254 final x = 1; 1272 final x = 1;
1255 } 1273 }
1256 class B extends A { 1274 class B extends A {
1257 m() { super.x = 2; } 1275 m() { super.x = 2; }
1258 } 1276 }
1259 ''', [MessageKind.SETTER_NOT_FOUND]); 1277 ''', [MessageKind.SETTER_NOT_FOUND_IN_SUPER]);
1260 1278
1261 // But non-final fields are OK: 1279 // But non-final fields are OK:
1262 checkWarningOn(''' 1280 checkWarningOn('''
1263 main() => new B().m(); 1281 main() => new B().m();
1264 class A { 1282 class A {
1265 int x = 1; 1283 int x = 1;
1266 } 1284 }
1267 class B extends A { 1285 class B extends A {
1268 m() { super.x = 2; } 1286 m() { super.x = 2; }
1269 } 1287 }
1270 ''', []); 1288 ''', []);
1271 } 1289 }
1272 1290
1273 1291
1274 /// Helper to test that [script] produces all the given [warnings]. 1292 /// Helper to test that [script] produces all the given [warnings].
1275 checkWarningOn(String script, List<MessageKind> warnings) { 1293 checkWarningOn(String script, List<MessageKind> warnings) {
1276 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2); 1294 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2);
1277 asyncTest(() => compileScript(script).then((compiler) { 1295 asyncTest(() => compileScript(script).then((compiler) {
1278 Expect.equals(0, compiler.errors.length); 1296 Expect.equals(0, compiler.errors.length);
1279 Expect.equals(warnings.length, compiler.warnings.length); 1297 Expect.equals(warnings.length, compiler.warnings.length);
1280 for (int i = 0; i < warnings.length; i++) { 1298 for (int i = 0; i < warnings.length; i++) {
1281 Expect.equals(warnings[i], compiler.warnings[i].message.kind); 1299 Expect.equals(warnings[i], compiler.warnings[i].message.kind);
1282 } 1300 }
1283 })); 1301 }));
1284 } 1302 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/warnings.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698