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

Unified Diff: lib/compiler/implementation/resolver.dart

Issue 11052012: Patch signatures checked in resolver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check moved. Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/resolver.dart
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
index 2bcf0aeda550c15a30f896b1913537577a32ac93..5ffda595bd2dd5661049c11bf6405d507fa24f54 100644
--- a/lib/compiler/implementation/resolver.dart
+++ b/lib/compiler/implementation/resolver.dart
@@ -133,9 +133,91 @@ class ResolverTask extends CompilerTask {
}
}
+ void checkMatchingPatchParameters(FunctionElement origin,
+ Link<Element> originParameters,
+ Link<Element> patchParameters) {
+ while (!originParameters.isEmpty()) {
+ Element originParameter = originParameters.head;
+ Element patchParameter = patchParameters.head;
+ // Hack: Use unparser to test parameter equality. This only works because
+ // we are restricting patch uses and the approach cannot be used
+ // elsewhere.
+ String originParameterText =
+ originParameter.parseNode(compiler).toString();
+ String patchParameterText =
+ patchParameter.parseNode(compiler).toString();
+ if (originParameterText != patchParameterText) {
+ error(originParameter.parseNode(compiler),
+ MessageKind.PATCH_PARAMETER_MISMATCH,
+ [origin.name, originParameterText, patchParameterText]);
+ }
+
+ originParameters = originParameters.tail;
+ patchParameters = patchParameters.tail;
+ }
+ }
+
void checkMatchingPatchSignatures(FunctionElement origin,
FunctionElement patch) {
- // TODO(johnniwinther): Stub. Implementation in a later CL.
+ // TODO(johnniwinther): Show both origin and patch locations on errors.
+ FunctionExpression originTree = compiler.withCurrentElement(origin, () {
+ return origin.parseNode(compiler);
+ });
+ FunctionSignature originSignature = compiler.withCurrentElement(origin, () {
+ return origin.computeSignature(compiler);
+ });
+ FunctionExpression patchTree = compiler.withCurrentElement(patch, () {
+ return patch.parseNode(compiler);
+ });
+ FunctionSignature patchSignature = compiler.withCurrentElement(patch, () {
+ return patch.computeSignature(compiler);
+ });
+
+ if (originSignature.returnType != patchSignature.returnType) {
+ compiler.withCurrentElement(patch, () {
+ Node errorNode =
+ patchTree.returnType !== null ? patchTree.returnType : patchTree;
+ error(errorNode, MessageKind.PATCH_RETURN_TYPE_MISMATCH, [origin.name,
+ originSignature.returnType, patchSignature.returnType]);
+ });
+ }
+ if (originSignature.requiredParameterCount !=
+ patchSignature.requiredParameterCount) {
+ compiler.withCurrentElement(patch, () {
+ error(patchTree,
+ MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH,
+ [origin.name, originSignature.requiredParameterCount,
+ patchSignature.requiredParameterCount]);
+ });
+ } else {
+ checkMatchingPatchParameters(origin,
+ originSignature.requiredParameters,
+ patchSignature.requiredParameters);
+ }
+ if (originSignature.optionalParameterCount != 0 &&
+ patchSignature.optionalParameterCount != 0) {
+ if (originSignature.optionalParametersAreNamed !=
+ patchSignature.optionalParametersAreNamed) {
+ compiler.withCurrentElement(patch, () {
+ error(patchTree,
+ MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH,
+ [origin.name]);
+ });
+ }
+ }
+ if (originSignature.optionalParameterCount !=
+ patchSignature.optionalParameterCount) {
+ compiler.withCurrentElement(patch, () {
+ error(patchTree,
+ MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH,
+ [origin.name, originSignature.optionalParameterCount,
+ patchSignature.optionalParameterCount]);
+ });
+ } else {
+ checkMatchingPatchParameters(origin,
+ originSignature.optionalParameters,
+ patchSignature.optionalParameters);
+ }
}
TreeElements resolveMethodElement(FunctionElement element) {
« no previous file with comments | « no previous file | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698