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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/member.dart

Issue 1685273002: fixes #25740, substitute type parameter bound taking into account outer scope type params (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge 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 | « no previous file | pkg/analyzer/lib/src/dart/element/type.dart » ('j') | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.src.dart.element.member; 5 library analyzer.src.dart.element.member;
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/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 return true; 894 return true;
895 } 895 }
896 } 896 }
897 } 897 }
898 } 898 }
899 return false; 899 return false;
900 } 900 }
901 } 901 }
902 902
903 /** 903 /**
904 * A type parameter defined inside of another parameterized type, where the
905 * values of the enclosing type parameters are known.
906 *
907 * For example:
908 *
909 * class C<T> {
910 * S m<S extends T>(S s);
911 * }
912 *
913 * If we have `C<num>.m` and we ask for the type parameter "S", we should get
914 * `<S extends num>` instead of `<S extends T>`. This is how the parameter
915 * and return types work, see: [FunctionType.parameters],
916 * [FunctionType.returnType], and [ParameterMember].
917 */
918 class TypeParameterMember extends Member implements TypeParameterElement {
919 @override
920 final DartType bound;
921
922 TypeParameterMember(
923 TypeParameterElement baseElement, DartType definingType, this.bound)
924 : super(baseElement, definingType);
925
926 @override
927 TypeParameterElement get baseElement =>
928 super.baseElement as TypeParameterElement;
929
930 @override
931 Element get enclosingElement => baseElement.enclosingElement;
932
933 @override
934 TypeParameterType get type => baseElement.type;
935
936 @override
937 accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this);
938
939 /**
940 * If the given [parameter]'s type is different when any type parameters from
941 * the defining type's declaration are replaced with the actual type
942 * arguments from the [definingType], create a parameter member representing
943 * the given parameter. Return the member that was created, or the base
944 * parameter if no member was created.
945 */
946 static TypeParameterElement from(
947 TypeParameterElement parameter, ParameterizedType definingType) {
948 if (parameter?.bound == null || definingType.typeArguments.isEmpty) {
949 return parameter;
950 }
951
952 DartType bound = parameter.bound;
953 List<DartType> argumentTypes = definingType.typeArguments;
954 List<DartType> parameterTypes =
955 TypeParameterTypeImpl.getTypes(definingType.typeParameters);
956 DartType substitutedBound =
957 bound.substitute2(argumentTypes, parameterTypes);
958 if (bound == substitutedBound) {
959 return parameter;
960 }
961 return new TypeParameterMember(parameter, definingType, substitutedBound);
962 }
963 }
964
965 /**
904 * A variable element defined in a parameterized type where the values of the 966 * A variable element defined in a parameterized type where the values of the
905 * type parameters are known. 967 * type parameters are known.
906 */ 968 */
907 abstract class VariableMember extends Member implements VariableElement { 969 abstract class VariableMember extends Member implements VariableElement {
908 @override 970 @override
909 final DartType type; 971 final DartType type;
910 972
911 /** 973 /**
912 * Initialize a newly created element to represent a variable, based on the 974 * Initialize a newly created element to represent a variable, based on the
913 * [baseElement], defined by the [definingType]. 975 * [baseElement], defined by the [definingType].
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 bool get isStatic => baseElement.isStatic; 1024 bool get isStatic => baseElement.isStatic;
963 1025
964 @override 1026 @override
965 void visitChildren(ElementVisitor visitor) { 1027 void visitChildren(ElementVisitor visitor) {
966 // TODO(brianwilkerson) We need to finish implementing the accessors used 1028 // TODO(brianwilkerson) We need to finish implementing the accessors used
967 // below so that we can safely invoke them. 1029 // below so that we can safely invoke them.
968 super.visitChildren(visitor); 1030 super.visitChildren(visitor);
969 safelyVisitChild(baseElement.initializer, visitor); 1031 safelyVisitChild(baseElement.initializer, visitor);
970 } 1032 }
971 } 1033 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/element/type.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698