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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 compiler.internalError("malformed send in new expression"); 1523 compiler.internalError("malformed send in new expression");
1524 } 1524 }
1525 } 1525 }
1526 1526
1527 /** 1527 /**
1528 * Try to resolve the constructor that is referred to by [node]. 1528 * Try to resolve the constructor that is referred to by [node].
1529 * Note: this function may return an ErroneousFunctionElement instead of 1529 * Note: this function may return an ErroneousFunctionElement instead of
1530 * [null], if there is no corresponding constructor, class or library. 1530 * [null], if there is no corresponding constructor, class or library.
1531 */ 1531 */
1532 FunctionElement resolveConstructor(NewExpression node) { 1532 FunctionElement resolveConstructor(NewExpression node) {
1533 FunctionElement constructor =
1534 node.accept(new ConstructorResolver(compiler, this));
1535 TypeAnnotation annotation = getTypeAnnotationFromSend(node.send); 1533 TypeAnnotation annotation = getTypeAnnotationFromSend(node.send);
1536 // TODO(karlklose): clean up: the type should be resolved in the 1534 // TODO(karlklose): clean up: the type should be resolved in the
1537 // constructor resolver visitor to avoid visiting the node twice. 1535 // constructor resolver visitor to avoid visiting the node twice.
1538 resolveTypeRequired(annotation); 1536 resolveTypeRequired(annotation);
1539 return constructor; 1537 ConstructorResolver visitor =
1538 new ConstructorResolver(compiler, this, node.isConst());
1539 return node.accept(visitor);
1540 } 1540 }
1541 1541
1542 Type resolveTypeRequired(TypeAnnotation node) { 1542 Type resolveTypeRequired(TypeAnnotation node) {
1543 bool old = typeRequired; 1543 bool old = typeRequired;
1544 typeRequired = true; 1544 typeRequired = true;
1545 Type result = resolveTypeAnnotation(node); 1545 Type result = resolveTypeAnnotation(node);
1546 typeRequired = old; 1546 typeRequired = old;
1547 return result; 1547 return result;
1548 } 1548 }
1549 1549
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 2345
2346 // TODO(ahe): This is temporary. 2346 // TODO(ahe): This is temporary.
2347 ClassElement get currentClass { 2347 ClassElement get currentClass {
2348 return enclosingElement.isMember() 2348 return enclosingElement.isMember()
2349 ? enclosingElement.getEnclosingClass() : null; 2349 ? enclosingElement.getEnclosingClass() : null;
2350 } 2350 }
2351 } 2351 }
2352 2352
2353 class ConstructorResolver extends CommonResolverVisitor<Element> { 2353 class ConstructorResolver extends CommonResolverVisitor<Element> {
2354 final ResolverVisitor resolver; 2354 final ResolverVisitor resolver;
2355 final bool inConstContext;
ahe 2012/09/21 09:35:45 What is this for?
2355 2356
2356 ConstructorResolver(Compiler compiler, this.resolver) : super(compiler); 2357 ConstructorResolver(Compiler compiler, this.resolver,
2358 [bool this.inConstContext = false])
ahe 2012/09/21 09:35:45 Why is this argument optional?
2359 : super(compiler);
2357 2360
2358 visitNode(Node node) { 2361 visitNode(Node node) {
2359 throw 'not supported'; 2362 throw 'not supported';
2360 } 2363 }
2361 2364
2362 FunctionElement lookupConstructor(ClassElement cls, 2365 FunctionElement lookupConstructor(ClassElement cls,
2363 Node diagnosticNode, 2366 Node diagnosticNode,
2364 SourceString constructorName) { 2367 SourceString constructorName) {
2365 cls.ensureResolved(compiler); 2368 cls.ensureResolved(compiler);
2366 Element result = cls.lookupConstructor(cls.name, constructorName); 2369 Element result = cls.lookupConstructor(cls.name, constructorName);
2367 if (result === null) { 2370 if (result === null) {
2368 String fullConstructorName = cls.name.slowToString(); 2371 String fullConstructorName = cls.name.slowToString();
2369 if (constructorName !== const SourceString('')) { 2372 if (constructorName !== const SourceString('')) {
2370 fullConstructorName = '$fullConstructorName' 2373 fullConstructorName = '$fullConstructorName'
2371 '.${constructorName.slowToString()}'; 2374 '.${constructorName.slowToString()}';
2372 } 2375 }
2373 ResolutionWarning warning = 2376 if (inConstContext) {
2374 new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR, 2377 error(diagnosticNode, MessageKind.CANNOT_FIND_CONSTRUCTOR,
ahe 2012/09/21 09:35:45 Why is this not returning an erroneous element?
2375 [fullConstructorName]); 2378 [fullConstructorName]);
2376 compiler.reportWarning(diagnosticNode, warning); 2379 } else {
2377 return new ErroneousFunctionElement(warning.message, cls); 2380 ResolutionWarning warning =
2381 new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR,
2382 [fullConstructorName]);
2383 compiler.reportWarning(diagnosticNode, warning);
2384 return new ErroneousFunctionElement(warning.message, cls);
2385 }
2378 } 2386 }
2379 return result; 2387 return result;
2380 } 2388 }
2381 2389
2382 visitNewExpression(NewExpression node) { 2390 visitNewExpression(NewExpression node) {
2383 Node selector = node.send.selector; 2391 Node selector = node.send.selector;
2384 Element e = visit(selector); 2392 Element e = visit(selector);
2385 if (!Element.isInvalid(e) && e.kind === ElementKind.CLASS) { 2393 if (!Element.isInvalid(e) && e.kind === ElementKind.CLASS) {
2386 ClassElement cls = e; 2394 ClassElement cls = e;
2387 cls.ensureResolved(compiler); 2395 cls.ensureResolved(compiler);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 TopScope(LibraryElement library) : super(null, library); 2566 TopScope(LibraryElement library) : super(null, library);
2559 Element lookup(SourceString name) { 2567 Element lookup(SourceString name) {
2560 return library.find(name); 2568 return library.find(name);
2561 } 2569 }
2562 2570
2563 Element add(Element newElement) { 2571 Element add(Element newElement) {
2564 throw "Cannot add an element in the top scope"; 2572 throw "Cannot add an element in the top scope";
2565 } 2573 }
2566 String toString() => '$element'; 2574 String toString() => '$element';
2567 } 2575 }
OLDNEW
« 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