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

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

Issue 1740923002: Propertly summarize LUB function types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.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) 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.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 6507 matching lines...) Expand 10 before | Expand all | Expand 10 after
6518 6518
6519 test_slot_reuse() { 6519 test_slot_reuse() {
6520 // Different compilation units have independent notions of slot id, so slot 6520 // Different compilation units have independent notions of slot id, so slot
6521 // ids should be reused. 6521 // ids should be reused.
6522 addNamedSource('/a.dart', 'part of foo; final v = 0;'); 6522 addNamedSource('/a.dart', 'part of foo; final v = 0;');
6523 serializeLibraryText('library foo; part "a.dart"; final w = 0;'); 6523 serializeLibraryText('library foo; part "a.dart"; final w = 0;');
6524 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1); 6524 expect(unlinkedUnits[0].variables[0].propagatedTypeSlot, 1);
6525 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1); 6525 expect(unlinkedUnits[1].variables[0].propagatedTypeSlot, 1);
6526 } 6526 }
6527 6527
6528 test_syntheticFunctionType_genericClosure() {
6529 if (skipFullyLinkedData) {
6530 return;
6531 }
6532 if (!strongMode) {
6533 // The test below uses generic comment syntax because proper generic
6534 // method syntax doesn't support generic closures. So it can only run in
6535 // strong mode.
6536 // TODO(paulberry): once proper generic method syntax supports generic
6537 // closures, rewrite the test below without using generic comment syntax,
6538 // and remove this hack. See dartbug.com/25819
6539 return;
6540 }
6541 UnlinkedVariable variable = serializeVariableText('''
6542 final v = f() ? /*<T>*/(T t) => 0 : /*<T>*/(T t) => 1;
6543 bool f() => true;
6544 ''');
6545 // The inferred type of `v` is currently `(Object) -> int` due to
6546 // dartbug.com/25802. TODO(paulberry): fix this test when the bug is fixed.
6547 EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot);
6548 checkLinkedTypeRef(
6549 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6550 expect(inferredType.syntheticParams, hasLength(1));
6551 checkLinkedTypeRef(inferredType.syntheticParams[0].type, 'dart:core',
6552 'dart:core', 'Object');
6553 }
6554
6555 test_syntheticFunctionType_genericClosure_inGenericFunction() {
6556 if (skipFullyLinkedData) {
6557 return;
6558 }
6559 if (!strongMode) {
6560 // The test below uses generic comment syntax because proper generic
6561 // method syntax doesn't support generic closures. So it can only run in
6562 // strong mode.
6563 // TODO(paulberry): once proper generic method syntax supports generic
6564 // closures, rewrite the test below without using generic comment syntax,
6565 // and remove this hack. See dartbug.com/25819
6566 return;
6567 }
6568 UnlinkedVariable variable = serializeExecutableText('''
6569 void f<T, U>(bool b) {
6570 final v = b ? /*<V>*/(T t, U u, V v) => 0 : /*<V>*/(T t, U u, V v) => 1;
6571 }
6572 ''').localVariables[0];
6573 // The inferred type of `v` is currently `(T, U, Object) -> int` due to
6574 // dartbug.com/25802. TODO(paulberry): fix this test when the bug is fixed.
6575 EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot);
6576 checkLinkedTypeRef(
6577 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6578 expect(inferredType.syntheticParams, hasLength(3));
6579 checkParamTypeRef(inferredType.syntheticParams[0].type, 2);
6580 checkParamTypeRef(inferredType.syntheticParams[1].type, 1);
6581 checkLinkedTypeRef(inferredType.syntheticParams[2].type, 'dart:core',
6582 'dart:core', 'Object');
6583 }
6584
6585 test_syntheticFunctionType_inGenericClass() {
6586 if (skipFullyLinkedData) {
6587 return;
6588 }
6589 UnlinkedVariable variable = serializeClassText('''
6590 class C<T, U> {
6591 var v = f() ? (T t, U u) => 0 : (T t, U u) => 1;
6592 }
6593 bool f() => false;
6594 ''').fields[0];
6595 EntityRef inferredType =
6596 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot);
6597 checkLinkedTypeRef(
6598 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6599 checkParamTypeRef(inferredType.syntheticParams[0].type, 2);
6600 checkParamTypeRef(inferredType.syntheticParams[1].type, 1);
6601 }
6602
6603 test_syntheticFunctionType_inGenericFunction() {
6604 if (skipFullyLinkedData) {
6605 return;
6606 }
6607 UnlinkedVariable variable = serializeExecutableText('''
6608 void f<T, U>(bool b) {
6609 var v = b ? (T t, U u) => 0 : (T t, U u) => 1;
6610 }
6611 ''').localVariables[0];
6612 EntityRef inferredType =
6613 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot);
6614 checkLinkedTypeRef(
6615 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6616 checkParamTypeRef(inferredType.syntheticParams[0].type, 2);
6617 checkParamTypeRef(inferredType.syntheticParams[1].type, 1);
6618 }
6619
6620 test_syntheticFunctionType_noArguments() {
6621 if (skipFullyLinkedData) {
6622 return;
6623 }
6624 UnlinkedVariable variable = serializeVariableText('''
6625 final v = f() ? () => 0 : () => 1;
6626 bool f() => true;
6627 ''');
6628 EntityRef propagatedType = getTypeRefForSlot(variable.propagatedTypeSlot);
6629 checkLinkedTypeRef(
6630 propagatedType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6631 expect(propagatedType.syntheticParams, isEmpty);
6632 }
6633
6634 test_syntheticFunctionType_withArguments() {
6635 if (skipFullyLinkedData) {
6636 return;
6637 }
6638 UnlinkedVariable variable = serializeVariableText('''
6639 final v = f() ? (int x, String y) => 0 : (int x, String y) => 1;
6640 bool f() => true;
6641 ''');
6642 EntityRef propagatedType = getTypeRefForSlot(variable.propagatedTypeSlot);
6643 checkTypeRef(
6644 propagatedType.syntheticReturnType, 'dart:core', 'dart:core', 'int');
6645 expect(propagatedType.syntheticParams, hasLength(2));
6646 checkTypeRef(propagatedType.syntheticParams[0].type, 'dart:core',
6647 'dart:core', 'int');
6648 checkTypeRef(propagatedType.syntheticParams[1].type, 'dart:core',
6649 'dart:core', 'String');
6650 }
6651
6528 test_type_arguments_explicit() { 6652 test_type_arguments_explicit() {
6529 EntityRef typeRef = serializeTypeText('List<int>'); 6653 EntityRef typeRef = serializeTypeText('List<int>');
6530 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', 6654 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List',
6531 allowTypeParameters: true, numTypeParameters: 1); 6655 allowTypeParameters: true, numTypeParameters: 1);
6532 expect(typeRef.typeArguments, hasLength(1)); 6656 expect(typeRef.typeArguments, hasLength(1));
6533 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 6657 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
6534 } 6658 }
6535 6659
6536 test_type_arguments_explicit_dynamic() { 6660 test_type_arguments_explicit_dynamic() {
6537 EntityRef typeRef = serializeTypeText('List<dynamic>'); 6661 EntityRef typeRef = serializeTypeText('List<dynamic>');
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
7069 expect(initializer.localFunctions, isEmpty); 7193 expect(initializer.localFunctions, isEmpty);
7070 expect(initializer.localVariables, isEmpty); 7194 expect(initializer.localVariables, isEmpty);
7071 } 7195 }
7072 7196
7073 test_variable_initializer_noInitializer() { 7197 test_variable_initializer_noInitializer() {
7074 UnlinkedVariable variable = serializeVariableText('var v;'); 7198 UnlinkedVariable variable = serializeVariableText('var v;');
7075 expect(variable.initializer, isNull); 7199 expect(variable.initializer, isNull);
7076 } 7200 }
7077 7201
7078 test_variable_initializer_withLocals() { 7202 test_variable_initializer_withLocals() {
7079 String text = 7203 String text = 'var v = <dynamic, dynamic>{"1": () { f1() {} var v1; }, '
7080 'var v = <dynamic, dynamic>{"1": () { f1() {} var v1; }, '
7081 '"2": () { f2() {} var v2; }};'; 7204 '"2": () { f2() {} var v2; }};';
7082 UnlinkedVariable variable = serializeVariableText(text); 7205 UnlinkedVariable variable = serializeVariableText(text);
7083 UnlinkedExecutable initializer = variable.initializer; 7206 UnlinkedExecutable initializer = variable.initializer;
7084 expect(initializer, isNotNull); 7207 expect(initializer, isNotNull);
7085 expect(initializer.nameOffset, text.indexOf('<dynamic, dynamic>{"1')); 7208 expect(initializer.nameOffset, text.indexOf('<dynamic, dynamic>{"1'));
7086 expect(initializer.name, isEmpty); 7209 expect(initializer.name, isEmpty);
7087 expect(initializer.localFunctions, hasLength(2)); 7210 expect(initializer.localFunctions, hasLength(2));
7088 // closure: () { f1() {} var v1; } 7211 // closure: () { f1() {} var v1; }
7089 { 7212 {
7090 UnlinkedExecutable closure = initializer.localFunctions[0]; 7213 UnlinkedExecutable closure = initializer.localFunctions[0];
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
7319 class _PrefixExpectation { 7442 class _PrefixExpectation {
7320 final ReferenceKind kind; 7443 final ReferenceKind kind;
7321 final String name; 7444 final String name;
7322 final String absoluteUri; 7445 final String absoluteUri;
7323 final String relativeUri; 7446 final String relativeUri;
7324 final int numTypeParameters; 7447 final int numTypeParameters;
7325 7448
7326 _PrefixExpectation(this.kind, this.name, 7449 _PrefixExpectation(this.kind, this.name,
7327 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 7450 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
7328 } 7451 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698