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

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

Issue 1509263002: Generic method subtyping. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/generated/type_system.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 engine.element; 5 library engine.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/src/generated/utilities_general.dart'; 10 import 'package:analyzer/src/generated/utilities_general.dart';
(...skipping 5058 matching lines...) Expand 10 before | Expand all | Expand 10 after
5069 } 5069 }
5070 FunctionTypeImpl otherType = object as FunctionTypeImpl; 5070 FunctionTypeImpl otherType = object as FunctionTypeImpl;
5071 if (boundTypeParameters.length != otherType.boundTypeParameters.length) { 5071 if (boundTypeParameters.length != otherType.boundTypeParameters.length) {
5072 return false; 5072 return false;
5073 } 5073 }
5074 // `<T>T -> T` should be equal to `<U>U -> U` 5074 // `<T>T -> T` should be equal to `<U>U -> U`
5075 // To test this, we instantiate both types with the same (unique) type 5075 // To test this, we instantiate both types with the same (unique) type
5076 // variables, and see if the result is equal. 5076 // variables, and see if the result is equal.
5077 if (boundTypeParameters.isNotEmpty) { 5077 if (boundTypeParameters.isNotEmpty) {
5078 List<DartType> instantiateTypeArgs = new List<DartType>(); 5078 List<DartType> instantiateTypeArgs = new List<DartType>();
5079 for (TypeParameterElement e in boundTypeParameters) { 5079 List<DartType> variablesThis = new List<DartType>();
5080 instantiateTypeArgs.add(new TypeParameterTypeImpl( 5080 List<DartType> variablesOther = new List<DartType>();
5081 new TypeParameterElementImpl(e.name, -1))); 5081 for (int i = 0; i < boundTypeParameters.length; i++) {
5082 TypeParameterElement pThis = boundTypeParameters[i];
5083 TypeParameterElement pOther = otherType.boundTypeParameters[i];
5084 TypeParameterTypeImpl pFresh = new TypeParameterTypeImpl(
5085 new TypeParameterElementImpl(pThis.name, -1));
5086 instantiateTypeArgs.add(pFresh);
5087 variablesThis.add(pThis.type);
5088 variablesOther.add(pOther.type);
5089 // Check that the bounds are equal after equating the previous
5090 // bound variables.
5091 if (pThis.bound?.substitute2(instantiateTypeArgs, variablesThis) !=
5092 pOther.bound?.substitute2(instantiateTypeArgs, variablesOther)) {
5093 return false;
5094 }
5082 } 5095 }
5083 // After instantiation, they will no longer have boundTypeParameters, 5096 // After instantiation, they will no longer have boundTypeParameters,
5084 // so we will continue below. 5097 // so we will continue below.
5085 return this.instantiate(instantiateTypeArgs) == 5098 return this.instantiate(instantiateTypeArgs) ==
5086 otherType.instantiate(instantiateTypeArgs); 5099 otherType.instantiate(instantiateTypeArgs);
5087 } 5100 }
5088 5101
5089 return returnType == otherType.returnType && 5102 return returnType == otherType.returnType &&
5090 TypeImpl.equalArrays( 5103 TypeImpl.equalArrays(
5091 normalParameterTypes, otherType.normalParameterTypes) && 5104 normalParameterTypes, otherType.normalParameterTypes) &&
(...skipping 11 matching lines...) Expand all
5103 _freeVariablesInFunctionType(this, freeVariables); 5116 _freeVariablesInFunctionType(this, freeVariables);
5104 5117
5105 Set<String> namesToAvoid = new HashSet<String>(); 5118 Set<String> namesToAvoid = new HashSet<String>();
5106 for (DartType arg in freeVariables) { 5119 for (DartType arg in freeVariables) {
5107 if (arg is TypeParameterType) { 5120 if (arg is TypeParameterType) {
5108 namesToAvoid.add(arg.displayName); 5121 namesToAvoid.add(arg.displayName);
5109 } 5122 }
5110 } 5123 }
5111 5124
5112 List<DartType> instantiateTypeArgs = new List<DartType>(); 5125 List<DartType> instantiateTypeArgs = new List<DartType>();
5126 List<DartType> variables = new List<DartType>();
5113 buffer.write("<"); 5127 buffer.write("<");
5114 for (TypeParameterElement e in boundTypeParameters) { 5128 for (TypeParameterElement e in boundTypeParameters) {
5115 if (e != boundTypeParameters[0]) { 5129 if (e != boundTypeParameters[0]) {
5116 buffer.write(","); 5130 buffer.write(",");
5117 } 5131 }
5118 String name = e.name; 5132 String name = e.name;
5119 int counter = 0; 5133 int counter = 0;
5120 while (!namesToAvoid.add(name)) { 5134 while (!namesToAvoid.add(name)) {
5121 // Unicode subscript-zero is U+2080, zero is U+0030. Other digits 5135 // Unicode subscript-zero is U+2080, zero is U+0030. Other digits
5122 // are sequential from there. Thus +0x2050 will get us the subscript. 5136 // are sequential from there. Thus +0x2050 will get us the subscript.
5123 String subscript = new String.fromCharCodes( 5137 String subscript = new String.fromCharCodes(
5124 counter.toString().codeUnits.map((n) => n + 0x2050)); 5138 counter.toString().codeUnits.map((n) => n + 0x2050));
5125 5139
5126 name = e.name + subscript; 5140 name = e.name + subscript;
5127 counter++; 5141 counter++;
5128 } 5142 }
5129 TypeParameterTypeImpl t = 5143 TypeParameterTypeImpl t =
5130 new TypeParameterTypeImpl(new TypeParameterElementImpl(name, -1)); 5144 new TypeParameterTypeImpl(new TypeParameterElementImpl(name, -1));
5131 t.appendTo(buffer); 5145 t.appendTo(buffer);
5132 instantiateTypeArgs.add(t); 5146 instantiateTypeArgs.add(t);
5147 variables.add(e.type);
5148 if (e.bound != null) {
5149 buffer.write(" extends ");
5150 TypeImpl renamed =
5151 e.bound.substitute2(instantiateTypeArgs, variables);
5152 renamed.appendTo(buffer);
5153 }
5133 } 5154 }
5134 buffer.write(">"); 5155 buffer.write(">");
5135 5156
5136 // Instantiate it and print the resulting type. After instantiation, it 5157 // Instantiate it and print the resulting type. After instantiation, it
5137 // will no longer have boundTypeParameters, so we will continue below. 5158 // will no longer have boundTypeParameters, so we will continue below.
5138 this.instantiate(instantiateTypeArgs).appendTo(buffer); 5159 this.instantiate(instantiateTypeArgs).appendTo(buffer);
5139 return; 5160 return;
5140 } 5161 }
5141 5162
5142 List<DartType> normalParameterTypes = this.normalParameterTypes; 5163 List<DartType> normalParameterTypes = this.normalParameterTypes;
(...skipping 5647 matching lines...) Expand 10 before | Expand all | Expand 10 after
10790 10811
10791 @override 10812 @override
10792 void visitElement(Element element) { 10813 void visitElement(Element element) {
10793 int offset = element.nameOffset; 10814 int offset = element.nameOffset;
10794 if (offset != -1) { 10815 if (offset != -1) {
10795 map[offset] = element; 10816 map[offset] = element;
10796 } 10817 }
10797 super.visitElement(element); 10818 super.visitElement(element);
10798 } 10819 }
10799 } 10820 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698