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

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

Issue 11412245: MalformedType used for all invalid type annotations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Bug fixes Created 8 years, 1 month 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: sdk/lib/_internal/compiler/implementation/ssa/builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index b654a69c5b6826035aca9baed36ea62a4a3d6d01..6cd42e0a76143bab46d658fd56507c2d10057ffe 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -107,6 +107,11 @@ class Interceptors {
return compiler.findHelper(const SourceString('throwRuntimeError'));
}
+ Element getThrowMalformedSubtypeError() {
+ return compiler.findHelper(
+ const SourceString('throwMalformedSubtypeError'));
+ }
+
Element getThrowAbstractClassInstantiationError() {
return compiler.findHelper(
const SourceString('throwAbstractClassInstantiationError'));
@@ -2648,6 +2653,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
DartType type = elements.getType(typeAnnotation);
+ if (type.isMalformed) {
+ String reasons = fetchReasonsFromMalformedType(type);
+ if (compiler.enableTypeAssertions) {
+ generateMalformedSubtypeError(node, expression, type, reasons);
+ } else {
+ generateRuntimeError(node, '$type is malformed: $reasons');
+ }
+ return;
+ }
HInstruction typeInfo = null;
if (RuntimeTypeInformation.hasTypeArguments(type)) {
pushInvokeHelper1(interceptors.getGetRuntimeTypeInfo(), expression);
@@ -3059,8 +3073,16 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
}
+ /**
+ * Documentation wanted -- johnniwinther
+ *
+ * Invariant: [argument] must not be malformed in checked mode.
+ */
HInstruction analyzeTypeArgument(DartType argument, Node currentNode) {
- if (argument == compiler.types.dynamicType) {
+ assert(invariant(currentNode,
+ !compiler.enableTypeAssertions || !argument.isMalformed,
+ message: '$argument is malformed in checked mode'));
+ if (argument == compiler.types.dynamicType || argument.isMalformed) {
// Represent [dynamic] as [null].
return graph.addConstantNull(constantSystem);
}
@@ -3188,7 +3210,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
<HInstruction>[typeInfoSetter, newObject, typeInfo]));
}
+ /**
+ * Documentation wanted -- johnniwinther
+ *
+ * Invariant: [type] must not be malformed in checked mode.
+ */
visitNewSend(Send node, InterfaceType type) {
+ assert(invariant(node,
+ !compiler.enableTypeAssertions || !type.isMalformed,
+ message: '$type is malformed in checked mode'));
bool isListConstructor = false;
computeType(element) {
Element originalElement = elements[node];
@@ -3428,10 +3458,17 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
existingArguments: existingArguments);
}
+ void generateMalformedSubtypeError(Node node, HInstruction value,
+ DartType type, String reasons) {
+ HInstruction typeString = addConstantString(node, type.toString());
+ HInstruction reasonsString = addConstantString(node, reasons);
+ Element helper = interceptors.getThrowMalformedSubtypeError();
+ pushInvokeHelper3(helper, value, typeString, reasonsString);
+ }
+
visitNewExpression(NewExpression node) {
Element element = elements[node.send];
- if (!Elements.isErroneousElement(element) &&
- !Elements.isMalformedElement(element)) {
+ if (!Elements.isErroneousElement(element)) {
FunctionElement function = element;
element = function.redirectionTarget;
}
@@ -3441,24 +3478,28 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
generateThrowNoSuchMethod(node.send,
getTargetName(error, 'constructor'),
argumentNodes: node.send.arguments);
- } else if (error.messageKind == MessageKind.CANNOT_RESOLVE) {
+ } else {
Message message = error.messageKind.message(error.messageArguments);
generateRuntimeError(node.send, message.toString());
- } else {
- compiler.internalError('unexpected unresolved constructor call',
- node: node);
}
} else if (node.isConst()) {
// TODO(karlklose): add type representation
ConstantHandler handler = compiler.constantHandler;
Constant constant = handler.compileNodeWithDefinitions(node, elements);
stack.add(graph.addConstant(constant));
- } else if (Elements.isMalformedElement(element)) {
- Message message =
- MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message([element]);
- generateRuntimeError(node.send, message.toString());
} else {
- visitNewSend(node.send, elements.getType(node));
+ DartType type = elements.getType(node);
+ if (compiler.enableTypeAssertions && type.isMalformed) {
+ ErroneousElement error;
+ type.forEachMalformedType((MalformedType malformedType) {
+ error = malformedType.element;
+ return false; // Visit the for malformed type only.
ahe 2012/11/30 15:44:07 I'm not sure I understand this comment.
Johnni Winther 2012/12/04 10:07:17 Changed to include all errors.
+ });
+ Message message = error.messageKind.message(error.messageArguments);
+ generateRuntimeError(node, message.toString());
+ } else {
+ visitNewSend(node.send, type);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698