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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 2376213003: Instantiate parameterized types of type parameters with 'dynamic' type arguments. (Closed)
Patch Set: Remove computeDefaultTypeArgument() and always use TypeSystem.instantiateToBounds(). Created 4 years, 2 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 599 }
600 600
601 @override 601 @override
602 int get version => 0; 602 int get version => 0;
603 603
604 @override 604 @override
605 DartType buildType( 605 DartType buildType(
606 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { 606 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
607 int numTypeParameters = _unlinkedClass.typeParameters.length; 607 int numTypeParameters = _unlinkedClass.typeParameters.length;
608 if (numTypeParameters != 0) { 608 if (numTypeParameters != 0) {
609 return new InterfaceTypeImpl.elementWithNameAndArgs(this, name, () { 609 List<DartType> typeArguments =
610 List<DartType> typeArguments = new List<DartType>(numTypeParameters); 610 new List<DartType>.generate(numTypeParameters, getTypeArgument);
611 for (int i = 0; i < numTypeParameters; i++) { 611 if (typeArguments.contains(null)) {
612 typeArguments[i] = 612 return context.typeSystem.instantiateToBounds(this.type);
613 getTypeArgument(i) ?? computeDefaultTypeArgument(i); 613 } else {
614 } 614 return new InterfaceTypeImpl.elementWithNameAndArgs(
615 return typeArguments; 615 this, name, () => typeArguments);
616 }); 616 }
617 } else { 617 } else {
618 return _type ??= new InterfaceTypeImpl(this); 618 return _type ??= new InterfaceTypeImpl(this);
619 } 619 }
620 } 620 }
621 621
622 @override 622 @override
623 PropertyAccessorElement getGetter(String getterName) { 623 PropertyAccessorElement getGetter(String getterName) {
624 for (PropertyAccessorElement accessor in accessors) { 624 for (PropertyAccessorElement accessor in accessors) {
625 if (accessor.isGetter && accessor.name == getterName) { 625 if (accessor.isGetter && accessor.name == getterName) {
626 return accessor; 626 return accessor;
(...skipping 2543 matching lines...) Expand 10 before | Expand all | Expand 10 after
3170 3170
3171 @override 3171 @override
3172 List<UnlinkedTypeParam> get unlinkedTypeParams => 3172 List<UnlinkedTypeParam> get unlinkedTypeParams =>
3173 _unlinkedTypedef.typeParameters; 3173 _unlinkedTypedef.typeParameters;
3174 3174
3175 @override 3175 @override
3176 DartType buildType( 3176 DartType buildType(
3177 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { 3177 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
3178 int numTypeParameters = _unlinkedTypedef.typeParameters.length; 3178 int numTypeParameters = _unlinkedTypedef.typeParameters.length;
3179 if (numTypeParameters != 0) { 3179 if (numTypeParameters != 0) {
3180 List<DartType> typeArguments = new List<DartType>(numTypeParameters); 3180 List<DartType> typeArguments =
3181 for (int i = 0; i < numTypeParameters; i++) { 3181 new List<DartType>.generate(numTypeParameters, getTypeArgument);
3182 typeArguments[i] = getTypeArgument(i) ?? computeDefaultTypeArgument(i); 3182 if (typeArguments.contains(null)) {
3183 return context.typeSystem
3184 .instantiateToBounds(new FunctionTypeImpl.forTypedef(this));
3185 } else {
3186 return new FunctionTypeImpl.elementWithNameAndArgs(
3187 this, name, typeArguments, true);
3183 } 3188 }
3184 return new FunctionTypeImpl.elementWithNameAndArgs(
3185 this, name, typeArguments, true);
3186 } else { 3189 } else {
3187 return _type ??= new FunctionTypeImpl.forTypedef(this); 3190 return _type ??= new FunctionTypeImpl.forTypedef(this);
3188 } 3191 }
3189 } 3192 }
3190 3193
3191 @override 3194 @override
3192 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3195 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3193 3196
3194 @override 3197 @override
3195 String toString() => '$enclosingElement.$name'; 3198 String toString() => '$enclosingElement.$name';
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
4400 */ 4403 */
4401 DartType get asStaticType => DynamicTypeImpl.instance; 4404 DartType get asStaticType => DynamicTypeImpl.instance;
4402 4405
4403 /** 4406 /**
4404 * If this element can be used in a getter context as a type inference 4407 * If this element can be used in a getter context as a type inference
4405 * dependency, return the [TypeInferenceNode] for the inferred type. 4408 * dependency, return the [TypeInferenceNode] for the inferred type.
4406 * Otherwise return `null`. 4409 * Otherwise return `null`.
4407 */ 4410 */
4408 TypeInferenceNode get asTypeInferenceNode => null; 4411 TypeInferenceNode get asTypeInferenceNode => null;
4409 4412
4413 @override
4414 ElementLocation get location => new ElementLocationImpl.con1(this);
4415
4410 /** 4416 /**
4411 * Return the type indicated by this element when it is used in a 4417 * Return the type indicated by this element when it is used in a
4412 * type instantiation context. If this element can't legally be 4418 * type instantiation context. If this element can't legally be
4413 * instantiated as a type, return the dynamic type. 4419 * instantiated as a type, return the dynamic type.
4414 * 4420 *
4415 * If the type is parameterized, [getTypeArgument] will be called to retrieve 4421 * If the type is parameterized, [getTypeArgument] will be called to retrieve
4416 * the type parameters. It should return `null` for unspecified type 4422 * the type parameters. It should return `null` for unspecified type
4417 * parameters. 4423 * parameters.
4418 */ 4424 */
4419 DartType buildType(DartType getTypeArgument(int i), 4425 DartType buildType(DartType getTypeArgument(int i),
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
5006 * there are no type parameters in scope. 5012 * there are no type parameters in scope.
5007 */ 5013 */
5008 TypeParameterizedElementMixin get _typeParameterContext; 5014 TypeParameterizedElementMixin get _typeParameterContext;
5009 5015
5010 @override 5016 @override
5011 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 5017 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
5012 5018
5013 @override 5019 @override
5014 String toString() => '$enclosingElement.$name'; 5020 String toString() => '$enclosingElement.$name';
5015 } 5021 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.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