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

Side by Side Diff: pkg/analyzer/test/src/summary/linker_test.dart

Issue 2754423002: Fail inference when an instance field is referenced. (Closed)
Patch Set: Created 3 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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:analyzer/dart/element/type.dart'; 5 import 'package:analyzer/dart/element/type.dart';
6 import 'package:analyzer/src/dart/element/element.dart'; 6 import 'package:analyzer/src/dart/element/element.dart';
7 import 'package:analyzer/src/summary/format.dart'; 7 import 'package:analyzer/src/summary/format.dart';
8 import 'package:analyzer/src/summary/idl.dart'; 8 import 'package:analyzer/src/summary/idl.dart';
9 import 'package:analyzer/src/summary/link.dart'; 9 import 'package:analyzer/src/summary/link.dart';
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 class E {} 341 class E {}
342 ''', 342 ''',
343 path: '/a.dart'); 343 path: '/a.dart');
344 addBundle('/a.ds', bundle); 344 addBundle('/a.ds', bundle);
345 createLinker(''' 345 createLinker('''
346 import 'a.dart'; 346 import 'a.dart';
347 var y = C.x; 347 var y = C.x;
348 '''); 348 ''');
349 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 349 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
350 expect(_getVariable(library.getContainedName('y')).inferredType.toString(), 350 expect(_getVariable(library.getContainedName('y')).inferredType.toString(),
351 '(D) → E'); 351 '(D) → dynamic');
Brian Wilkerson 2017/03/17 22:39:42 Are these tests worth keeping? If we're not doing
scheglov 2017/03/18 01:54:52 It is partially a question of taste. Tests in this
352 } 352 }
353 353
354 void test_inferredType_instanceField_conditional_genericFunctions() { 354 void test_inferredType_instanceField_conditional_genericFunctions() {
355 createLinker(''' 355 createLinker('''
356 class C { 356 class C {
357 final f = true ? <T>(T t) => 0 : <T>(T t) => 1; 357 final f = true ? <T>(T t) => 0 : <T>(T t) => 1;
358 } 358 }
359 '''); 359 ''');
360 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 360 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
361 library.libraryCycleForLink.ensureLinked(); 361 library.libraryCycleForLink.ensureLinked();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 var bundle = createPackageBundle( 482 var bundle = createPackageBundle(
483 ''' 483 '''
484 class C { 484 class C {
485 var f = 0; // Inferred type: int 485 var f = 0; // Inferred type: int
486 } 486 }
487 ''', 487 ''',
488 path: '/a.dart'); 488 path: '/a.dart');
489 addBundle('/a.ds', bundle); 489 addBundle('/a.ds', bundle);
490 createLinker(''' 490 createLinker('''
491 import 'a.dart'; 491 import 'a.dart';
492 var x = new C().f; // Inferred type: int 492 var x = new C().f; // Inferred type: dynamic
493 '''); 493 ''');
494 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 494 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
495 expect(_getVariable(library.getContainedName('x')).inferredType.toString(), 495 expect(_getVariable(library.getContainedName('x')).inferredType.toString(),
496 'int'); 496 'dynamic');
497 } 497 }
498 498
499 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() { 499 void test_inferredTypeFromOutsideBuildUnit_instanceField_toInstanceField() {
500 var bundle = createPackageBundle( 500 var bundle = createPackageBundle(
501 ''' 501 '''
502 class C { 502 class C {
503 var f = 0; // Inferred type: int 503 var f = 0; // Inferred type: int
504 } 504 }
505 ''', 505 ''',
506 path: '/a.dart'); 506 path: '/a.dart');
507 addBundle('/a.ds', bundle); 507 addBundle('/a.ds', bundle);
508 createLinker(''' 508 createLinker('''
509 import 'a.dart'; 509 import 'a.dart';
510 class D { 510 class D {
511 var g = new C().f; // Inferred type: int 511 var g = new C().f; // Inferred type: int
512 } 512 }
513 '''); 513 ''');
514 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri); 514 LibraryElementForLink library = linker.getLibrary(linkerInputs.testDartUri);
515 ClassElementForLink_Class classD = library.getContainedName('D'); 515 ClassElementForLink_Class classD = library.getContainedName('D');
516 expect(classD.fields[0].inferredType.toString(), 'int'); 516 expect(classD.fields[0].inferredType.toString(), 'dynamic');
517 } 517 }
518 518
519 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() { 519 void test_inferredTypeFromOutsideBuildUnit_methodParamType_viaGeneric() {
520 var bundle = createPackageBundle( 520 var bundle = createPackageBundle(
521 ''' 521 '''
522 class B { 522 class B {
523 T f<T>(T t) => t; 523 T f<T>(T t) => t;
524 } 524 }
525 class C extends B { 525 class C extends B {
526 f<T>(t) => t; // Inferred param type: T 526 f<T>(t) => t; // Inferred param type: T
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 */ 965 */
966 EntityRef _lookupInferredType(LinkedUnit unit, int slot) { 966 EntityRef _lookupInferredType(LinkedUnit unit, int slot) {
967 for (EntityRef ref in unit.types) { 967 for (EntityRef ref in unit.types) {
968 if (ref.slot == slot) { 968 if (ref.slot == slot) {
969 return ref; 969 return ref;
970 } 970 }
971 } 971 }
972 return null; 972 return null;
973 } 973 }
974 } 974 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/strong_mode.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698