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

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
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/builder.dart
diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
index 93d83a5dd78b566ace22ff9ddf3636c648c07274..513052a73e1f53f0786c0536bf37cf7a7e46262f 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'));
}
@@ -2510,19 +2514,19 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
}
+ Element constructor = elements[node];
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.
@@ -2534,7 +2538,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
inputs.add(analyzeTypeArgument(argument, node));
});
- HType elementType = computeType(element);
+ HType elementType = computeType(constructor);
HInstruction newInstance = new HInvokeStatic(inputs, elementType);
pushWithPosition(newInstance, node);
}
@@ -2604,9 +2608,16 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
}
+ void generateRuntimeError(Node node, String message) {
+ DartString messageObject = new DartString.literal(message);
+ 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)) {
+ if (element != null && element.isErroneous()) {
ErroneousElement error = element;
Message message = error.errorMessage;
if (message.kind === MessageKind.CANNOT_FIND_CONSTRUCTOR) {
@@ -2626,9 +2637,11 @@ 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',
- node: node);
+ compiler.internalError('unexpected unresolved constructor call',
+ node: node);
}
} else if (node.isConst()) {
// TODO(karlklose): add type representation
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698