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

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

Issue 1643403002: Test and fix a few more corner cases of summarizing type inference. (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/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 3974 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 ' abstract class D<U, V> { Map<V, U> get v; }', 3985 ' abstract class D<U, V> { Map<V, U> get v; }',
3986 className: 'C'); 3986 className: 'C');
3987 EntityRef type = getTypeRefForSlot(cls.fields[0].inferredTypeSlot); 3987 EntityRef type = getTypeRefForSlot(cls.fields[0].inferredTypeSlot);
3988 // Check that v has inferred type Map<T, int>. 3988 // Check that v has inferred type Map<T, int>.
3989 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', 3989 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map',
3990 allowTypeParameters: true, numTypeParameters: 2); 3990 allowTypeParameters: true, numTypeParameters: 2);
3991 checkParamTypeRef(type.typeArguments[0], 1); 3991 checkParamTypeRef(type.typeArguments[0], 1);
3992 checkLinkedTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int'); 3992 checkLinkedTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int');
3993 } 3993 }
3994 3994
3995 test_inferred_type_refers_to_function_typed_parameter_type_generic_class() {
3996 if (!strongMode || skipFullyLinkedData) {
3997 return;
3998 }
3999 UnlinkedClass cls = serializeClassText(
4000 'class C<T, U> extends D<U, int> { void f(int x, g) {} }'
4001 ' abstract class D<V, W> { void f(int x, W g(V s)); }',
4002 className: 'C');
4003 EntityRef type =
4004 getTypeRefForSlot(cls.executables[0].parameters[1].inferredTypeSlot);
4005 // Check that parameter g's inferred type is the type implied by D.f's 1st
4006 // (zero-based) parameter.
4007 expect(type.implicitFunctionTypeIndices, [1]);
4008 expect(type.paramReference, 0);
4009 expect(type.typeArguments, hasLength(2));
4010 checkParamTypeRef(type.typeArguments[0], 1);
4011 checkTypeRef(type.typeArguments[1], 'dart:core', 'dart:core', 'int');
4012 expect(type.reference,
4013 greaterThanOrEqualTo(unlinkedUnits[0].references.length));
4014 LinkedReference linkedReference =
4015 linked.units[0].references[type.reference];
4016 expect(linkedReference.dependency, 0);
4017 expect(linkedReference.kind, ReferenceKind.method);
4018 expect(linkedReference.name, 'f');
4019 expect(linkedReference.numTypeParameters, 2);
4020 expect(linkedReference.unit, 0);
4021 expect(linkedReference.containingReference, isNot(0));
4022 expect(linkedReference.containingReference, lessThan(type.reference));
4023 checkReferenceIndex(linkedReference.containingReference, null, null, 'D',
4024 numTypeParameters: 2);
4025 }
4026
4027 test_inferred_type_refers_to_function_typed_parameter_type_other_lib() {
4028 if (!strongMode || skipFullyLinkedData) {
4029 return;
4030 }
4031 addNamedSource('/a.dart', 'import "b.dart"; abstract class D extends E {}');
4032 addNamedSource(
4033 '/b.dart', 'abstract class E { void f(int x, int g(String s)); }');
4034 UnlinkedClass cls = serializeClassText(
4035 'import "a.dart"; class C extends D { void f(int x, g) {} }');
4036 EntityRef type =
4037 getTypeRefForSlot(cls.executables[0].parameters[1].inferredTypeSlot);
4038 // Check that parameter g's inferred type is the type implied by D.f's 1st
4039 // (zero-based) parameter.
4040 expect(type.implicitFunctionTypeIndices, [1]);
4041 expect(type.paramReference, 0);
4042 expect(type.typeArguments, isEmpty);
4043 expect(type.reference,
4044 greaterThanOrEqualTo(unlinkedUnits[0].references.length));
4045 LinkedReference linkedReference =
4046 linked.units[0].references[type.reference];
4047 int expectedDep =
4048 checkHasDependency(absUri('/b.dart'), 'b.dart', fullyLinked: true);
4049 expect(linkedReference.dependency, expectedDep);
4050 expect(linkedReference.kind, ReferenceKind.method);
4051 expect(linkedReference.name, 'f');
4052 expect(linkedReference.numTypeParameters, 0);
4053 expect(linkedReference.unit, 0);
4054 expect(linkedReference.containingReference, isNot(0));
4055 expect(linkedReference.containingReference, lessThan(type.reference));
4056 checkReferenceIndex(
4057 linkedReference.containingReference, absUri('/b.dart'), 'b.dart', 'E');
4058 }
4059
3995 test_inferred_type_refers_to_method_function_typed_parameter_type() { 4060 test_inferred_type_refers_to_method_function_typed_parameter_type() {
3996 if (!strongMode || skipFullyLinkedData) { 4061 if (!strongMode || skipFullyLinkedData) {
3997 return; 4062 return;
3998 } 4063 }
3999 UnlinkedClass cls = serializeClassText( 4064 UnlinkedClass cls = serializeClassText(
4000 'class C extends D { void f(int x, g) {} }' 4065 'class C extends D { void f(int x, g) {} }'
4001 ' abstract class D { void f(int x, int g(String s)); }', 4066 ' abstract class D { void f(int x, int g(String s)); }',
4002 className: 'C'); 4067 className: 'C');
4003 EntityRef type = 4068 EntityRef type =
4004 getTypeRefForSlot(cls.executables[0].parameters[1].inferredTypeSlot); 4069 getTypeRefForSlot(cls.executables[0].parameters[1].inferredTypeSlot);
4005 // Check that parameter g's inferred type is the type implied by D.f's 1st 4070 // Check that parameter g's inferred type is the type implied by D.f's 1st
4006 // (zero-based) parameter. 4071 // (zero-based) parameter.
4007 expect(type.implicitFunctionTypeIndices, hasLength(1)); 4072 expect(type.implicitFunctionTypeIndices, [1]);
4008 expect(type.implicitFunctionTypeIndices[0], 1);
4009 expect(type.paramReference, 0); 4073 expect(type.paramReference, 0);
4010 expect(type.typeArguments, isEmpty); 4074 expect(type.typeArguments, isEmpty);
4011 expect(type.reference, 4075 expect(type.reference,
4012 greaterThanOrEqualTo(unlinkedUnits[0].references.length)); 4076 greaterThanOrEqualTo(unlinkedUnits[0].references.length));
4013 LinkedReference linkedReference = 4077 LinkedReference linkedReference =
4014 linked.units[0].references[type.reference]; 4078 linked.units[0].references[type.reference];
4015 expect(linkedReference.dependency, 0); 4079 expect(linkedReference.dependency, 0);
4016 expect(linkedReference.kind, ReferenceKind.method); 4080 expect(linkedReference.kind, ReferenceKind.method);
4017 expect(linkedReference.name, 'f'); 4081 expect(linkedReference.name, 'f');
4018 expect(linkedReference.numTypeParameters, 0); 4082 expect(linkedReference.numTypeParameters, 0);
4019 expect(linkedReference.unit, 0); 4083 expect(linkedReference.unit, 0);
4020 expect(linkedReference.containingReference, isNot(0)); 4084 expect(linkedReference.containingReference, isNot(0));
4021 expect(linkedReference.containingReference, lessThan(type.reference)); 4085 expect(linkedReference.containingReference, lessThan(type.reference));
4022 checkReferenceIndex(linkedReference.containingReference, null, null, 'D'); 4086 checkReferenceIndex(linkedReference.containingReference, null, null, 'D');
4023 } 4087 }
4024 4088
4025 test_inferred_type_refers_to_setter_function_typed_parameter_type() { 4089 test_inferred_type_refers_to_setter_function_typed_parameter_type() {
4026 if (!strongMode || skipFullyLinkedData) { 4090 if (!strongMode || skipFullyLinkedData) {
4027 return; 4091 return;
4028 } 4092 }
4029 UnlinkedClass cls = serializeClassText( 4093 UnlinkedClass cls = serializeClassText(
4030 'class C extends D { void set f(g) {} }' 4094 'class C extends D { void set f(g) {} }'
4031 ' abstract class D { void set f(int g(String s)); }', 4095 ' abstract class D { void set f(int g(String s)); }',
4032 className: 'C'); 4096 className: 'C');
4033 EntityRef type = 4097 EntityRef type =
4034 getTypeRefForSlot(cls.executables[0].parameters[0].inferredTypeSlot); 4098 getTypeRefForSlot(cls.executables[0].parameters[0].inferredTypeSlot);
4035 // Check that parameter g's inferred type is the type implied by D.f's 1st 4099 // Check that parameter g's inferred type is the type implied by D.f's 1st
4036 // (zero-based) parameter. 4100 // (zero-based) parameter.
4037 expect(type.implicitFunctionTypeIndices, hasLength(1)); 4101 expect(type.implicitFunctionTypeIndices, [0]);
4038 expect(type.implicitFunctionTypeIndices[0], 0);
4039 expect(type.paramReference, 0); 4102 expect(type.paramReference, 0);
4040 expect(type.typeArguments, isEmpty); 4103 expect(type.typeArguments, isEmpty);
4041 expect(type.reference, 4104 expect(type.reference,
4042 greaterThanOrEqualTo(unlinkedUnits[0].references.length)); 4105 greaterThanOrEqualTo(unlinkedUnits[0].references.length));
4043 LinkedReference linkedReference = 4106 LinkedReference linkedReference =
4044 linked.units[0].references[type.reference]; 4107 linked.units[0].references[type.reference];
4045 expect(linkedReference.dependency, 0); 4108 expect(linkedReference.dependency, 0);
4046 expect(linkedReference.kind, ReferenceKind.propertyAccessor); 4109 expect(linkedReference.kind, ReferenceKind.propertyAccessor);
4047 expect(linkedReference.name, 'f='); 4110 expect(linkedReference.name, 'f=');
4048 expect(linkedReference.numTypeParameters, 0); 4111 expect(linkedReference.numTypeParameters, 0);
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
5020 final String absoluteUri; 5083 final String absoluteUri;
5021 final String relativeUri; 5084 final String relativeUri;
5022 final int numTypeParameters; 5085 final int numTypeParameters;
5023 5086
5024 _PrefixExpectation(this.kind, this.name, 5087 _PrefixExpectation(this.kind, this.name,
5025 {this.inLibraryDefiningUnit: false, 5088 {this.inLibraryDefiningUnit: false,
5026 this.absoluteUri, 5089 this.absoluteUri,
5027 this.relativeUri, 5090 this.relativeUri,
5028 this.numTypeParameters: 0}); 5091 this.numTypeParameters: 0});
5029 } 5092 }
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