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

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

Issue 10868069: Throw a runtime error when trying to call a constructor of a class that could not be resolved. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 f7b0ba49b7d7de16ee31a8dc3fc408aad5f545d9..9aeaf19fae7b0b16f4e30b88213f8926ed154294 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -101,6 +101,10 @@ class Interceptors {
return compiler.findHelper(const SourceString('unwrapException'));
}
+ Element getThrowRuntimeError() {
+ return compiler.findHelper(const SourceString('throwRuntimeError'));
+ }
+
Element getClosureConverter() {
return compiler.findHelper(const SourceString('convertDartClosureToJS'));
}
@@ -2304,7 +2308,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
}
- visitNewSend(Send node) {
+ visitNewSend(Send node, Element constructor) {
ngeoffray 2012/08/24 15:43:48 I'd rather not have this new parameter. The send a
karlklose 2012/08/28 09:09:15 Done.
computeType(element) {
Element originalElement = elements[node];
if (originalElement.getEnclosingClass() === compiler.listClass) {
@@ -2322,25 +2326,24 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
Selector selector = elements.getSelector(node);
- Element element = elements[node];
- if (compiler.enqueuer.resolution.getCachedElements(element) === null) {
- compiler.internalError("Unresolved element: $element", node: node);
+ if (compiler.enqueuer.resolution.getCachedElements(constructor) === null) {
+ compiler.internalError("Unresolved element: $constructor", node: node);
}
- FunctionElement functionElement = element;
- element = functionElement.defaultImplementation;
- HInstruction target = new HStatic(element);
+ FunctionElement functionElement = constructor;
+ constructor = functionElement.defaultImplementation;
+ HInstruction target = new HStatic(constructor);
add(target);
var inputs = <HInstruction>[];
inputs.add(target);
bool succeeded = addStaticSendArgumentsToList(selector, node.arguments,
- element, inputs);
+ constructor, inputs);
if (!succeeded) {
// TODO(ngeoffray): Match the VM behavior and throw an
// exception at runtime.
compiler.cancel('Unimplemented non-matching static call', node: node);
}
- HType elementType = computeType(element);
+ HType elementType = computeType(constructor);
HInstruction newInstance = new HInvokeStatic(inputs, elementType);
pushWithPosition(newInstance, node);
@@ -2424,6 +2427,13 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
}
+ void generateRuntimeError(Node node, String message) {
+ final messageObject = new DartString.literal(message.toString());
ngeoffray 2012/08/24 15:43:48 final -> DartString (for consistency)
ngeoffray 2012/08/24 15:43:48 message is already a String.
karlklose 2012/08/28 09:09:15 Done.
karlklose 2012/08/28 09:09:15 Done.
+ HInstruction errorMessage = graph.addConstantString(messageObject, node);
+ Element helper = interceptors.getThrowRuntimeError();
+ pushInvokeHelper1(helper, errorMessage);
+ }
+
visitNewExpression(NewExpression node) {
Element element = elements[node.send];
if (Element.isInvalid(element)) {
@@ -2446,6 +2456,8 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
HInstruction arguments = new HLiteralList(inputs);
add(arguments);
pushInvokeHelper3(helper, receiver, name, arguments);
+ } else if (message.kind === MessageKind.CANNOT_RESOLVE) {
+ generateRuntimeError(node.send, message.message);
} else {
compiler.cancel('Unimplemented unresolved constructor call',
ngeoffray 2012/08/24 15:43:48 Can this still happen?
karlklose 2012/08/28 09:09:15 It should not. I changed it to an internal error s
node: node);
@@ -2456,7 +2468,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
Constant constant = handler.compileNodeWithDefinitions(node, elements);
stack.add(graph.addConstant(constant));
} else {
- visitNewSend(node.send);
+ visitNewSend(node.send, element);
}
}

Powered by Google App Engine
This is Rietveld 408576698