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

Unified Diff: lib/compiler/implementation/ssa/builder.dart

Issue 11273034: Make unmatched static call a runtime error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a bug. 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
Index: lib/compiler/implementation/ssa/builder.dart
diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
index fbffcde651006065b105446665748ec054d53735..b0aa6c24fee94396ea56c480684f1d7d23f8e32d 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -2296,6 +2296,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
push(result);
}
+ void pushInvokeHelper4(Element helper, HInstruction a0, HInstruction a1,
+ HInstruction a2, HInstruction a3) {
+ HInstruction reference = new HStatic(helper);
+ add(reference);
+ List<HInstruction> inputs = <HInstruction>[reference, a0, a1, a2, a3];
+ HInstruction result = new HInvokeStatic(inputs);
+ push(result);
+ }
+
visitOperatorSend(node) {
assert(node.selector is Operator);
if (!methodInterceptionEnabled) {
@@ -2729,15 +2738,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
} else if (element.isFunction() || element.isGenerativeConstructor()) {
// TODO(5347): Try to avoid the need for calling [implementation] before
// calling [addStaticSendArgumentsToList].
+ FunctionElement function = element.implementation;
bool succeeded = addStaticSendArgumentsToList(selector, node.arguments,
- element.implementation,
- inputs);
+ function, inputs);
if (!succeeded) {
- // TODO(ngeoffray): Match the VM behavior and throw an
- // exception at runtime.
- compiler.cancel('Unimplemented non-matching static call', node: node);
+ generateWrongArgumentCountError(node, element,
+ argumentNodes: node.arguments);
+ } else {
+ push(new HInvokeSuper(inputs));
}
- push(new HInvokeSuper(inputs));
} else {
target = new HInvokeSuper(inputs);
add(target);
@@ -2936,9 +2945,9 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
constructor.implementation,
inputs);
if (!succeeded) {
- // TODO(ngeoffray): Match the VM behavior and throw an
- // exception at runtime.
- compiler.cancel('Unimplemented non-matching static call', node: node);
+ generateWrongArgumentCountError(node, constructor,
+ argumentNodes: node.arguments);
+ return;
}
TypeAnnotation annotation = node.getTypeAnnotation();
@@ -2979,7 +2988,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
argumentNodes: node.arguments);
return;
}
- if (identical(element, compiler.assertMethod) && !compiler.enableUserAssertions) {
+ if (identical(element, compiler.assertMethod)
+ && !compiler.enableUserAssertions) {
stack.add(graph.addConstantNull(constantSystem));
return;
}
@@ -2998,9 +3008,9 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
element.implementation,
inputs);
if (!succeeded) {
- // TODO(ngeoffray): Match the VM behavior and throw an
- // exception at runtime.
- compiler.cancel('Unimplemented non-matching static call', node: node);
+ generateWrongArgumentCountError(node, element,
+ argumentNodes: node.arguments);
+ return;
}
// TODO(kasperl): Try to use the general inlining infrastructure for
@@ -3056,7 +3066,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
void generateThrowNoSuchMethod(Node diagnosticNode,
String methodName,
{Link<Node> argumentNodes,
- List<HInstruction> argumentValues}) {
+ List<HInstruction> argumentValues,
+ List<String> existingArguments}) {
Element helper =
compiler.findHelper(const SourceString('throwNoSuchMethod'));
Constant receiverConstant =
@@ -3076,7 +3087,42 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
HInstruction arguments = new HLiteralList(argumentValues);
add(arguments);
- pushInvokeHelper3(helper, receiver, name, arguments);
+ HInstruction existingNamesList;
+ if (existingArguments != null) {
+ List<HInstruction> existingNames = <HInstruction>[];
+ for (String name in existingArguments) {
+ HInstruction nameConstant =
+ graph.addConstantString(new DartString.literal(name),
+ diagnosticNode, constantSystem);
+ existingNames.add(nameConstant);
+ }
+ existingNamesList = new HLiteralList(existingNames);
+ add(existingNamesList);
+ } else {
+ existingNamesList = graph.addConstantNull(constantSystem);
+ }
+ pushInvokeHelper4(helper, receiver, name, arguments, existingNamesList);
+ }
+
+ /**
+ * Generate code to throw a [NoSuchMethodError] exception for calling a
+ * method with a wrong number of arguments or mismatching named optional
+ * arguments.
+ */
+ void generateWrongArgumentCountError(Node diagnosticNode,
+ FunctionElement function,
+ {Link<Node> argumentNodes,
ahe 2012/10/25 14:07:27 I still don't understand why these arguments are o
karlklose 2012/10/26 11:08:48 Nice catch, removed argumentValues and made argume
+ List<HInstruction> argumentValues}) {
+ List<String> existingArguments = <String>[];
+ FunctionSignature signature = function.computeSignature(compiler);
+ signature.forEachParameter((Element parameter) {
+ existingArguments.add(parameter.name.slowToString());
+ });
+ generateThrowNoSuchMethod(diagnosticNode,
+ function.name.slowToString(),
+ argumentNodes: argumentNodes,
+ argumentValues: argumentValues,
+ existingArguments: existingArguments);
}
visitNewExpression(NewExpression node) {

Powered by Google App Engine
This is Rietveld 408576698