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

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 2271223004: fix #27110, mark implicit downcasts for op assign (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library analyzer.test.src.task.strong.checker_test; 5 library analyzer.test.src.task.strong.checker_test;
6 6
7 import '../../../reflective_tests.dart'; 7 import '../../../reflective_tests.dart';
8 import 'strong_test_helper.dart'; 8 import 'strong_test_helper.dart';
9 9
10 void main() { 10 void main() {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 class D { 263 class D {
264 D operator +(D d) => null; 264 D operator +(D d) => null;
265 } 265 }
266 266
267 foo() => new A(); 267 foo() => new A();
268 268
269 test() { 269 test() {
270 int x = 0; 270 int x = 0;
271 x += 5; 271 x += 5;
272 /*error:STATIC_TYPE_ERROR*/x += /*error:INVALID_ASSIGNMENT*/3.14; 272 x += /*error:INVALID_ASSIGNMENT*/3.14;
Jennifer Messerly 2016/08/25 22:27:15 this is still detected as a sideways cast by _chec
273 273
274 double y = 0.0; 274 double y = 0.0;
275 y += 5; 275 y += 5;
276 y += 3.14; 276 y += 3.14;
277 277
278 num z = 0; 278 num z = 0;
279 z += 5; 279 z += 5;
280 z += 3.14; 280 z += 3.14;
281 281
282 x = /*info:DOWN_CAST_IMPLICIT*/x + z; 282 x = /*info:DOWN_CAST_IMPLICIT*/x + z;
283 x += /*info:DOWN_CAST_IMPLICIT*/z; 283 /*info:DOWN_CAST_IMPLICIT*/x += z;
Jennifer Messerly 2016/08/25 22:27:15 this is an example of where DDC would've been putt
284 y = y + z; 284 y = y + z;
285 y += z; 285 y += z;
286 286
287 dynamic w = 42; 287 dynamic w = 42;
288 x += /*info:DYNAMIC_CAST*/w; 288 /*info:DOWN_CAST_IMPLICIT*/x += /*info:DYNAMIC_CAST*/w;
Jennifer Messerly 2016/08/25 22:27:15 here too. we need two casts. the first because "w"
289 y += /*info:DYNAMIC_CAST*/w; 289 y += /*info:DYNAMIC_CAST*/w;
290 z += /*info:DYNAMIC_CAST*/w; 290 z += /*info:DYNAMIC_CAST*/w;
291 291
292 A a = new A(); 292 A a = new A();
293 B b = new B(); 293 B b = new B();
294 var c = foo(); 294 var c = foo();
295 a = a * b; 295 a = a * b;
296 a *= b; 296 a *= b;
297 a *= /*info:DYNAMIC_CAST*/c; 297 a *= /*info:DYNAMIC_CAST*/c;
298 a /= b; 298 a /= b;
299 a ~/= b; 299 a ~/= b;
300 a %= b; 300 a %= b;
301 a += b; 301 a += b;
302 a += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a; 302 a += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a;
303 a -= b; 303 a -= b;
304 /*error:STATIC_TYPE_ERROR*/b -= /*error:INVALID_ASSIGNMENT*/b; 304 b -= /*error:INVALID_ASSIGNMENT*/b;
Jennifer Messerly 2016/08/25 22:27:15 same reason here as to why this went away.
305 a <<= b; 305 a <<= b;
306 a >>= b; 306 a >>= b;
307 a &= b; 307 a &= b;
308 a ^= b; 308 a ^= b;
309 a |= b; 309 a |= b;
310 /*info:DYNAMIC_INVOKE*/c += b; 310 /*info:DYNAMIC_INVOKE*/c += b;
311 311
312 var d = new D(); 312 var d = new D();
313 a[b] += d; 313 a[b] += d;
314 a[/*info:DYNAMIC_CAST*/c] += d; 314 a[/*info:DYNAMIC_CAST*/c] += d;
315 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d; 315 a[/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d;
316 a[b] += /*info:DYNAMIC_CAST*/c; 316 a[b] += /*info:DYNAMIC_CAST*/c;
317 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z; 317 a[b] += /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z;
318 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; 318 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d;
319 } 319 }
320 '''); 320 ''');
321 } 321 }
322 322
323 void test_compoundAssignment_returnsDynamic() {
324 checkFile(r'''
325 class Foo {
326 operator +(other) => null;
327 }
328
329 main() {
330 var foo = new Foo();
331 foo = /*info:DYNAMIC_CAST*/foo + 1;
332 /*info:DYNAMIC_CAST*/foo += 1;
Jennifer Messerly 2016/08/25 22:27:15 previously this line was an error, inconsistent wi
333 }
334 ''');
335 }
336
323 void test_constructorInvalid() { 337 void test_constructorInvalid() {
324 // Regression test for https://github.com/dart-lang/sdk/issues/26695 338 // Regression test for https://github.com/dart-lang/sdk/issues/26695
325 checkFile(''' 339 checkFile('''
326 class A { 340 class A {
327 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {} 341 B({ /*error:FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR*/this.test: 1.0 }) {}
328 final double test = 0.0; 342 final double test = 0.0;
329 } 343 }
330 '''); 344 ''');
331 } 345 }
332 346
(...skipping 3392 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 // Regression test for https://github.com/dart-lang/sdk/issues/25069 3739 // Regression test for https://github.com/dart-lang/sdk/issues/25069
3726 checkFile(''' 3740 checkFile('''
3727 typedef int Foo(); 3741 typedef int Foo();
3728 void foo() {} 3742 void foo() {}
3729 void main () { 3743 void main () {
3730 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); 3744 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo();
3731 } 3745 }
3732 '''); 3746 ''');
3733 } 3747 }
3734 } 3748 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698