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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/modelx.dart

Issue 24153008: Check if signatures are compatible in a redirecting factory before synthesizing a call in the infer… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/resolution/members.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 elements.modelx; 5 library elements.modelx;
6 6
7 import 'dart:collection' show LinkedHashMap; 7 import 'dart:collection' show LinkedHashMap;
8 8
9 import 'elements.dart'; 9 import 'elements.dart';
10 import '../../compiler.dart' as api; 10 import '../../compiler.dart' as api;
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 } 1182 }
1183 1183
1184 int get parameterCount => requiredParameterCount + optionalParameterCount; 1184 int get parameterCount => requiredParameterCount + optionalParameterCount;
1185 1185
1186 /** 1186 /**
1187 * Check whether a function with this signature can be used instead of a 1187 * Check whether a function with this signature can be used instead of a
1188 * function with signature [signature] without causing a `noSuchMethod` 1188 * function with signature [signature] without causing a `noSuchMethod`
1189 * exception/call. 1189 * exception/call.
1190 */ 1190 */
1191 bool isCompatibleWith(FunctionSignature signature) { 1191 bool isCompatibleWith(FunctionSignature signature) {
1192 if (optionalParametersAreNamed != signature.optionalParametersAreNamed) {
1193 return false;
1194 }
1195 if (optionalParametersAreNamed) { 1192 if (optionalParametersAreNamed) {
1193 if (!signature.optionalParametersAreNamed) {
1194 return requiredParameterCount == signature.parameterCount;
1195 }
1196 // If both signatures have named parameters, then they must have
1197 // the same number of required parameters, and the names in
1198 // [signature] must all be in [:this:].
1196 if (requiredParameterCount != signature.requiredParameterCount) { 1199 if (requiredParameterCount != signature.requiredParameterCount) {
1197 return false; 1200 return false;
1198 } 1201 }
1202 Set<String> names = optionalParameters.toList().map(
1203 (Element element) => element.name.slowToString()).toSet();
1199 for (Element namedParameter in signature.optionalParameters) { 1204 for (Element namedParameter in signature.optionalParameters) {
1200 if (!optionalParameters.contains(namedParameter)) { 1205 if (!names.contains(namedParameter.name.slowToString())) {
1201 return false; 1206 return false;
1202 } 1207 }
1203 } 1208 }
1204 } else { 1209 } else {
1210 if (signature.optionalParametersAreNamed) return false;
1205 // There must be at least as many arguments as in the other signature, but 1211 // There must be at least as many arguments as in the other signature, but
1206 // this signature must not have more required parameters. Having more 1212 // this signature must not have more required parameters. Having more
1207 // optional parameters is not a problem, they simply are never provided 1213 // optional parameters is not a problem, they simply are never provided
1208 // by call sites of a call to a method with the other signature. 1214 // by call sites of a call to a method with the other signature.
1209 if (requiredParameterCount > signature.requiredParameterCount || 1215 int otherTotalCount = signature.parameterCount;
1210 requiredParameterCount < signature.parameterCount || 1216 return requiredParameterCount <= otherTotalCount
1211 parameterCount < signature.parameterCount) { 1217 && parameterCount >= otherTotalCount;
1212 return false;
1213 }
1214 } 1218 }
1215 return true; 1219 return true;
1216 } 1220 }
1217 } 1221 }
1218 1222
1219 class FunctionElementX extends ElementX implements FunctionElement { 1223 class FunctionElementX extends ElementX implements FunctionElement {
1220 FunctionExpression cachedNode; 1224 FunctionExpression cachedNode;
1221 DartType type; 1225 DartType type;
1222 final Modifiers modifiers; 1226 final Modifiers modifiers;
1223 1227
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 2221
2218 MetadataAnnotation ensureResolved(Compiler compiler) { 2222 MetadataAnnotation ensureResolved(Compiler compiler) {
2219 if (resolutionState == STATE_NOT_STARTED) { 2223 if (resolutionState == STATE_NOT_STARTED) {
2220 compiler.resolver.resolveMetadataAnnotation(this); 2224 compiler.resolver.resolveMetadataAnnotation(this);
2221 } 2225 }
2222 return this; 2226 return this;
2223 } 2227 }
2224 2228
2225 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2229 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2226 } 2230 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698