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

Unified Diff: lib/compiler/implementation/resolver.dart

Issue 10870037: Throw a NoSuchMethodException when attempting to call an undefined constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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/resolver.dart
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
index 496b2a2a0140023e76d87ab83820e8bd16a95bef..736f4837653336939231b6185a5fb73c18e7afb0 100644
--- a/lib/compiler/implementation/resolver.dart
+++ b/lib/compiler/implementation/resolver.dart
@@ -1530,13 +1530,13 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
* [null], if there is no corresponding constructor, class or library.
*/
FunctionElement resolveConstructor(NewExpression node) {
- FunctionElement constructor =
- node.accept(new ConstructorResolver(compiler, this));
TypeAnnotation annotation = getTypeAnnotationFromSend(node.send);
// TODO(karlklose): clean up: the type should be resolved in the
// constructor resolver visitor to avoid visiting the node twice.
resolveTypeRequired(annotation);
- return constructor;
+ ConstructorResolver visitor =
+ new ConstructorResolver(compiler, this, node.isConst());
+ return node.accept(visitor);
}
Type resolveTypeRequired(TypeAnnotation node) {
@@ -2352,8 +2352,11 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
class ConstructorResolver extends CommonResolverVisitor<Element> {
final ResolverVisitor resolver;
+ final bool inConstContext;
ahe 2012/09/21 09:35:45 What is this for?
- ConstructorResolver(Compiler compiler, this.resolver) : super(compiler);
+ ConstructorResolver(Compiler compiler, this.resolver,
+ [bool this.inConstContext = false])
ahe 2012/09/21 09:35:45 Why is this argument optional?
+ : super(compiler);
visitNode(Node node) {
throw 'not supported';
@@ -2370,11 +2373,16 @@ class ConstructorResolver extends CommonResolverVisitor<Element> {
fullConstructorName = '$fullConstructorName'
'.${constructorName.slowToString()}';
}
- ResolutionWarning warning =
- new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR,
- [fullConstructorName]);
- compiler.reportWarning(diagnosticNode, warning);
- return new ErroneousFunctionElement(warning.message, cls);
+ if (inConstContext) {
+ error(diagnosticNode, MessageKind.CANNOT_FIND_CONSTRUCTOR,
ahe 2012/09/21 09:35:45 Why is this not returning an erroneous element?
+ [fullConstructorName]);
+ } else {
+ ResolutionWarning warning =
+ new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR,
+ [fullConstructorName]);
+ compiler.reportWarning(diagnosticNode, warning);
+ return new ErroneousFunctionElement(warning.message, cls);
+ }
}
return result;
}
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | tests/language/call_nonexistent_constructor_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698