| OLD | NEW |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 testThis, | 81 testThis, |
| 82 testSuperCalls, | 82 testSuperCalls, |
| 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 ], (f) => f())); | 92 ], (f) => f())); |
| 92 } | 93 } |
| 93 | 94 |
| 94 Future testSupertypeOrder() { | 95 Future testSupertypeOrder() { |
| 95 return Future.wait([ | 96 return Future.wait([ |
| 96 MockCompiler.create((MockCompiler compiler) { | 97 MockCompiler.create((MockCompiler compiler) { |
| 97 compiler.parseScript(""" | 98 compiler.parseScript(""" |
| 98 class I1 {} | 99 class I1 {} |
| 99 class I2 {} | 100 class I2 {} |
| 100 class J1 extends K1 {} | 101 class J1 extends K1 {} |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 }"""; | 1136 }"""; |
| 1136 asyncTest(() => compileScript(script2).then((compiler) { | 1137 asyncTest(() => compileScript(script2).then((compiler) { |
| 1137 expect(compiler, | 1138 expect(compiler, |
| 1138 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], | 1139 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], |
| 1139 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 1140 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 1140 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, | 1141 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, |
| 1141 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, | 1142 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, |
| 1142 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); | 1143 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); |
| 1143 })); | 1144 })); |
| 1144 } | 1145 } |
| 1146 |
| 1147 testCantAssignMethods() { |
| 1148 checkWarningOn(String script, List<String> errorLocations) { |
| 1149 asyncTest(() => compileScript(script).then((compiler) { |
| 1150 Expect.equals(0, compiler.errors.length); |
| 1151 Expect.equals(errorLocations.length, compiler.warnings.length); |
| 1152 for (var i = 0; i < errorLocations.length; i++) { |
| 1153 Expect.equals(MessageKind.ASSIGNING_METHOD, |
| 1154 compiler.warnings[i].message.kind); |
| 1155 Expect.equals(script.indexOf(errorLocations[i]), |
| 1156 compiler.warnings[i].node.getBeginToken().charOffset); |
| 1157 } |
| 1158 })); |
| 1159 } |
| 1160 |
| 1161 // Can't override local functions |
| 1162 checkWarningOn(''' |
| 1163 main() { |
| 1164 mname() { mname = 2; }; |
| 1165 mname(); |
| 1166 } |
| 1167 ''', ['mname = 2']); |
| 1168 |
| 1169 checkWarningOn(''' |
| 1170 main() { |
| 1171 mname() { }; |
| 1172 mname = 3; |
| 1173 } |
| 1174 ''', ['mname = 3']); |
| 1175 |
| 1176 // Can't override top-level functions |
| 1177 checkWarningOn(''' |
| 1178 m() {} |
| 1179 main() { m = 4; } |
| 1180 ''', ['m = 4']); |
| 1181 |
| 1182 // Can't override instance methods |
| 1183 checkWarningOn(''' |
| 1184 main() { new B().bar(); } |
| 1185 class B { |
| 1186 mname() {} |
| 1187 bar() { |
| 1188 mname = () => null; |
| 1189 } |
| 1190 } |
| 1191 ''', ['mname = () => null']); |
| 1192 |
| 1193 // Can't override super methods |
| 1194 checkWarningOn(''' |
| 1195 main() { new B().bar(); } |
| 1196 class A { |
| 1197 mname() {} |
| 1198 } |
| 1199 class B extends A { |
| 1200 bar() { |
| 1201 super.mname = () => 6; |
| 1202 } |
| 1203 } |
| 1204 ''', ['mname = () => 6']); |
| 1205 |
| 1206 // But fields are OK: |
| 1207 checkWarningOn(''' |
| 1208 main() { new B().bar(); } |
| 1209 class A { |
| 1210 int fname; |
| 1211 } |
| 1212 class B extends A { |
| 1213 bar() { |
| 1214 super.fname = 3; |
| 1215 } |
| 1216 } |
| 1217 ''', []); |
| 1218 |
| 1219 // And we shouldn't confuse index operators either: |
| 1220 checkWarningOn(''' |
| 1221 main() { new B().bar(); } |
| 1222 class B { |
| 1223 operator[]=(x, y) {} |
| 1224 bar() { |
| 1225 this[1] = 3; // This is OK |
| 1226 } |
| 1227 } |
| 1228 ''', []); |
| 1229 checkWarningOn(''' |
| 1230 main() { new B().bar(); } |
| 1231 class A { |
| 1232 operator[]=(x, y) {} |
| 1233 } |
| 1234 class B extends A { |
| 1235 bar() { |
| 1236 super[1] = 3; // This is OK |
| 1237 } |
| 1238 } |
| 1239 ''', []); |
| 1240 } |
| OLD | NEW |