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

Unified Diff: frog/leg/typechecker.dart

Issue 9835007: Typecheck constructor calls. I'm pretty sure about the call to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: take peter's commments into account Created 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/typechecker.dart
diff --git a/frog/leg/typechecker.dart b/frog/leg/typechecker.dart
index ef555b2a420e88e1cba9224a75c35fbeffce3301..315f88bdfbf3115f359c7af331d52a3daa31943e 100644
--- a/frog/leg/typechecker.dart
+++ b/frog/leg/typechecker.dart
@@ -358,13 +358,28 @@ class TypeCheckerVisitor implements Visitor<Type> {
return types.dynamicType;
}
- Link<Type> analyzeArguments(Link<Node> arguments) {
- LinkBuilder<Type> builder = new LinkBuilder<Type>();
- while(!arguments.isEmpty()) {
- builder.addLast(analyze(arguments.head));
- arguments = arguments.tail;
+ void analyzeArguments(Send send, FunctionType funType) {
+ Link<Node> arguments = send.arguments;
+ if (funType === null) {
+ while(!arguments.isEmpty()) {
+ analyze(arguments.head);
+ arguments = arguments.tail;
+ }
+ } else {
+ Link<Type> parameterTypes = funType.parameterTypes;
+ while (!arguments.isEmpty() && !parameterTypes.isEmpty()) {
+ checkAssignable(arguments.head, parameterTypes.head,
+ analyze(arguments.head));
+ arguments = arguments.tail;
+ parameterTypes = parameterTypes.tail;
+ }
+ if (!arguments.isEmpty()) {
+ reportTypeWarning(arguments.head, MessageKind.ADDITIONAL_ARGUMENT);
+ } else if (!parameterTypes.isEmpty()) {
+ reportTypeWarning(send, MessageKind.MISSING_ARGUMENT,
+ [parameterTypes.head]);
+ }
}
- return builder.toLink();
}
Type visitSend(Send node) {
@@ -416,7 +431,6 @@ class TypeCheckerVisitor implements Visitor<Type> {
fail(node.receiver, 'function object invocation unimplemented');
} else {
- Link<Type> argumentTypes = analyzeArguments(node.arguments);
FunctionType funType;
if (node.receiver !== null) {
Type receiverType = analyze(node.receiver);
@@ -448,21 +462,7 @@ class TypeCheckerVisitor implements Visitor<Type> {
fail(node, 'unexpected element kind ${element.kind}');
}
}
- Link<Type> parameterTypes = funType.parameterTypes;
- Link<Node> argumentNodes = node.arguments;
- while (!argumentTypes.isEmpty() && !parameterTypes.isEmpty()) {
- checkAssignable(argumentNodes.head, parameterTypes.head,
- argumentTypes.head);
- argumentTypes = argumentTypes.tail;
- parameterTypes = parameterTypes.tail;
- argumentNodes = argumentNodes.tail;
- }
- if (!argumentTypes.isEmpty()) {
- reportTypeWarning(argumentNodes.head, MessageKind.ADDITIONAL_ARGUMENT);
- } else if (!parameterTypes.isEmpty()) {
- reportTypeWarning(node, MessageKind.MISSING_ARGUMENT,
- [parameterTypes.head]);
- }
+ analyzeArguments(node, funType);
return funType.returnType;
}
}
@@ -510,6 +510,8 @@ class TypeCheckerVisitor implements Visitor<Type> {
}
Type visitNewExpression(NewExpression node) {
+ Element element = elements[node.send];
+ analyzeArguments(node.send, computeType(element));
return analyze(node.send.selector);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698