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

Unified Diff: pkg/analyzer/lib/src/dart/element/type.dart

Issue 2762863002: Issue 28580. Relax instantiate to bounds. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/dart/element/type.dart
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index 21a57e4c2ef0049f71f411d4df53c596a9814611..1447f33a43213b29a7b3c509db9dc6160d1b0749 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -2470,6 +2470,11 @@ abstract class TypeImpl implements DartType {
final String name;
/**
+ * The cached value for [hasTypeParameterReferenceInBound].
+ */
+ bool _hasTypeParameterReferenceInBound;
+
+ /**
* Initialize a newly created type to be declared by the given [element] and
* to have the given [name].
*/
@@ -2481,6 +2486,33 @@ abstract class TypeImpl implements DartType {
@override
Element get element => _element;
+ /**
+ * Return `true` if the type is parameterized and has a type parameter with
+ * the bound that references a type parameter.
+ */
+ bool get hasTypeParameterReferenceInBound {
+ if (_hasTypeParameterReferenceInBound == null) {
+ bool hasTypeParameterReference(DartType type) {
+ if (type is TypeParameterType) {
+ return true;
Leaf 2017/03/21 04:58:42 This should only return true for other type parame
scheglov 2017/03/21 05:42:00 I'm sorry, I must have missed something in the spe
Leaf 2017/03/21 13:24:53 Ignore everything I said, I was thinking about som
+ } else if (type is ParameterizedType) {
+ return type.typeArguments.any(hasTypeParameterReference);
+ } else {
Leaf 2017/03/21 04:58:42 Are the new function types instances of Parameteri
scheglov 2017/03/21 05:42:00 AFAIK these are also FunctionType(s), so Parameter
+ return false;
+ }
+ }
+
+ Element element = this.element;
+ if (element is TypeParameterizedElement) {
+ _hasTypeParameterReferenceInBound = element.typeParameters
+ .any((parameter) => hasTypeParameterReference(parameter.bound));
+ } else {
+ _hasTypeParameterReferenceInBound = false;
+ }
+ }
+ return _hasTypeParameterReferenceInBound;
+ }
+
@override
bool get isBottom => false;

Powered by Google App Engine
This is Rietveld 408576698