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

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

Issue 1899873003: Support for type inference of top-level function invocations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
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 library analyzer.test.src.summary.resynthesize_ast_test; 5 library analyzer.test.src.summary.resynthesize_ast_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/element/element.dart'; 9 import 'package:analyzer/src/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 71
72 @override 72 @override
73 DartSdk createDartSdk() => AbstractContextTest.SHARED_STRONG_MOCK_SDK; 73 DartSdk createDartSdk() => AbstractContextTest.SHARED_STRONG_MOCK_SDK;
74 74
75 @override 75 @override
76 AnalysisOptionsImpl createOptions() => new AnalysisOptionsImpl() 76 AnalysisOptionsImpl createOptions() => new AnalysisOptionsImpl()
77 ..enableGenericMethods = true 77 ..enableGenericMethods = true
78 ..strongMode = true; 78 ..strongMode = true;
79 79
80 void fail_infer_invokeMethodRef_function() {
81 // TODO(scheglov) requires an element for top-level functions
82 // TODO(scheglov) add more tests - imported, and with prefix
83 var unit = checkFile(r'''
84 int m() => 0;
85 var a = m();
86 ''');
87 expect(unit.topLevelVariables[0].type.toString(), 'int');
88 }
89
90 @override 80 @override
91 @failingTest 81 @failingTest
92 void test_blockBodiedLambdas_async_allReturnsAreValues() { 82 void test_blockBodiedLambdas_async_allReturnsAreValues() {
93 super.test_blockBodiedLambdas_async_allReturnsAreValues(); 83 super.test_blockBodiedLambdas_async_allReturnsAreValues();
94 } 84 }
95 85
96 @override 86 @override
97 @failingTest 87 @failingTest
98 void test_blockBodiedLambdas_async_alReturnsAreFutures() { 88 void test_blockBodiedLambdas_async_alReturnsAreFutures() {
99 super.test_blockBodiedLambdas_async_alReturnsAreFutures(); 89 super.test_blockBodiedLambdas_async_alReturnsAreFutures();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 void test_infer_invokeConstructor_unnamed_synthetic() { 389 void test_infer_invokeConstructor_unnamed_synthetic() {
400 checkFile(r''' 390 checkFile(r'''
401 class A {} 391 class A {}
402 class B<T> {} 392 class B<T> {}
403 var a = new A(); 393 var a = new A();
404 var b1 = new B(); 394 var b1 = new B();
405 var b2 = new B<int>(); 395 var b2 = new B<int>();
406 '''); 396 ''');
407 } 397 }
408 398
399 void test_infer_invokeMethodRef_function() {
400 var unit = checkFile(r'''
401 int m() => 0;
402 var a = m();
403 ''');
404 expect(unit.topLevelVariables[0].type.toString(), 'int');
405 }
406
407 void test_infer_invokeMethodRef_function_generic() {
408 var unit = checkFile(r'''
409 /*=Map<int, V>*/ m/*<V>*/(/*=V*/ a) => null;
410 var a = m(2.3);
411 ''');
412 expect(unit.topLevelVariables[0].type.toString(), 'Map<int, double>');
413 }
414
415 void test_infer_invokeMethodRef_function_importedWithPrefix() {
416 addFile(
417 r'''
418 int m() => 0;
419 ''',
420 name: '/a.dart');
421 var unit = checkFile(r'''
422 import 'a.dart' as p;
423 var a = p.m();
424 ''');
425 expect(unit.topLevelVariables[0].type.toString(), 'int');
426 }
427
409 void test_infer_invokeMethodRef_method() { 428 void test_infer_invokeMethodRef_method() {
410 var unit = checkFile(r''' 429 var unit = checkFile(r'''
411 class A { 430 class A {
412 int m() => 0; 431 int m() => 0;
413 } 432 }
414 var a = new A(); 433 var a = new A();
415 var b = a.m(); 434 var b = a.m();
416 '''); 435 ''');
417 expect(unit.topLevelVariables[1].type.toString(), 'int'); 436 expect(unit.topLevelVariables[1].type.toString(), 'int');
418 } 437 }
419 438
420 void test_infer_invokeMethodRef_method_g() { 439 void test_infer_invokeMethodRef_method_g() {
421 var unit = checkFile(r''' 440 var unit = checkFile(r'''
422 class A { 441 class A {
423 /*=T*/ m/*<T>*/(/*=T*/ a) => null; 442 /*=T*/ m/*<T>*/(/*=T*/ a) => null;
424 } 443 }
425 var a = new A(); 444 var a = new A();
426 var b = a.m(1.0); 445 var b = a.m(1.0);
427 '''); 446 ''');
428 expect(unit.topLevelVariables[1].type.toString(), 'double'); 447 expect(unit.topLevelVariables[1].type.toString(), 'double');
429 } 448 }
430 449
431 void test_infer_invokeMethodRef_method_gg() {
432 var unit = checkFile(r'''
433 class A<K> {
434 /*=Map<K, V>*/ m/*<V>*/(/*=V*/ a) => null;
435 }
436 var a = new A<int>();
437 var b = a.m(1.0);
438 ''');
439 expect(unit.topLevelVariables[1].type.toString(), 'Map<int, double>');
440 }
441
442 void test_infer_invokeMethodRef_method_genericSequence() { 450 void test_infer_invokeMethodRef_method_genericSequence() {
443 var unit = checkFile(r''' 451 var unit = checkFile(r'''
444 class A<T> { 452 class A<T> {
445 B<T> b = new B<T>(); 453 B<T> b = new B<T>();
446 } 454 }
447 class B<K> { 455 class B<K> {
448 C<List<K>, int> c = new C<List<K>, int>(); 456 C<List<K>, int> c = new C<List<K>, int>();
449 } 457 }
450 class C<K, V> { 458 class C<K, V> {
451 Map<K, V> m() => null; 459 Map<K, V> m() => null;
452 } 460 }
453 var a = new A<double>(); 461 var a = new A<double>();
454 var v = a.b.c.m(); 462 var v = a.b.c.m();
455 '''); 463 ''');
456 expect(unit.topLevelVariables[1].type.toString(), 'Map<List<double>, int>'); 464 expect(unit.topLevelVariables[1].type.toString(), 'Map<List<double>, int>');
457 } 465 }
458 466
467 void test_infer_invokeMethodRef_method_gg() {
468 var unit = checkFile(r'''
469 class A<K> {
470 /*=Map<K, V>*/ m/*<V>*/(/*=V*/ a) => null;
471 }
472 var a = new A<int>();
473 var b = a.m(1.0);
474 ''');
475 expect(unit.topLevelVariables[1].type.toString(), 'Map<int, double>');
476 }
477
459 void test_infer_invokeMethodRef_method_importedWithPrefix() { 478 void test_infer_invokeMethodRef_method_importedWithPrefix() {
460 addFile( 479 addFile(
461 r''' 480 r'''
462 class A { 481 class A {
463 int m() => 0; 482 int m() => 0;
464 } 483 }
465 var a = new A(); 484 var a = new A();
466 ''', 485 ''',
467 name: '/a.dart'); 486 name: '/a.dart');
468 var unit = checkFile(r''' 487 var unit = checkFile(r'''
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 761 }
743 762
744 UnlinkedUnit definingUnit = _getUnlinkedUnit(librarySource); 763 UnlinkedUnit definingUnit = _getUnlinkedUnit(librarySource);
745 LinkedLibraryBuilder linkedLibrary = 764 LinkedLibraryBuilder linkedLibrary =
746 prelink(definingUnit, getPart, getImport); 765 prelink(definingUnit, getPart, getImport);
747 linkedLibrary.dependencies.skip(1).forEach((LinkedDependency d) { 766 linkedLibrary.dependencies.skip(1).forEach((LinkedDependency d) {
748 _serializeLibrary(resolveRelativeUri(d.uri)); 767 _serializeLibrary(resolveRelativeUri(d.uri));
749 }); 768 });
750 } 769 }
751 } 770 }
OLDNEW
« pkg/analyzer/lib/src/summary/link.dart ('K') | « pkg/analyzer/lib/src/summary/link.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698