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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 21065002: Treat ambiguous types as malformed. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Status updated. Created 7 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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 return compiler.types.voidType.element; 1421 return compiler.types.voidType.element;
1422 } else if (identical(stringValue, 'dynamic')) { 1422 } else if (identical(stringValue, 'dynamic')) {
1423 return compiler.dynamicClass; 1423 return compiler.dynamicClass;
1424 } else { 1424 } else {
1425 return scope.lookup(typeName.source); 1425 return scope.lookup(typeName.source);
1426 } 1426 }
1427 } 1427 }
1428 } 1428 }
1429 1429
1430 DartType resolveTypeAnnotation(MappingVisitor visitor, TypeAnnotation node, 1430 DartType resolveTypeAnnotation(MappingVisitor visitor, TypeAnnotation node,
1431 {bool malformedIsError: false, 1431 {bool malformedIsError: false}) {
1432 bool ambiguousIsError: false}) {
1433 Identifier typeName; 1432 Identifier typeName;
1434 SourceString prefixName; 1433 SourceString prefixName;
1435 Send send = node.typeName.asSend(); 1434 Send send = node.typeName.asSend();
1436 if (send != null) { 1435 if (send != null) {
1437 // The type name is of the form [: prefix . identifier :]. 1436 // The type name is of the form [: prefix . identifier :].
1438 prefixName = send.receiver.asIdentifier().source; 1437 prefixName = send.receiver.asIdentifier().source;
1439 typeName = send.selector.asIdentifier(); 1438 typeName = send.selector.asIdentifier();
1440 } else { 1439 } else {
1441 typeName = node.typeName.asIdentifier(); 1440 typeName = node.typeName.asIdentifier();
1442 } 1441 }
1443 1442
1444 Element element = resolveTypeName(visitor.scope, prefixName, typeName); 1443 Element element = resolveTypeName(visitor.scope, prefixName, typeName);
1445 DartType type; 1444 DartType type;
1446 1445
1447 DartType reportFailureAndCreateType(DualKind messageKind, 1446 DartType reportFailureAndCreateType(DualKind messageKind,
1448 Map messageArguments, 1447 Map messageArguments,
1449 {DartType userProvidedBadType, 1448 {DartType userProvidedBadType}) {
1450 bool isError: false, 1449 if (malformedIsError) {
1451 bool isAmbiguous: false}) {
1452 if (isError) {
1453 visitor.error(node, messageKind.error, messageArguments); 1450 visitor.error(node, messageKind.error, messageArguments);
1454 } else { 1451 } else {
1455 visitor.warning(node, messageKind.warning, messageArguments); 1452 visitor.warning(node, messageKind.warning, messageArguments);
1456 } 1453 }
1457 var erroneousElement = new ErroneousElementX( 1454 var erroneousElement = new ErroneousElementX(
1458 messageKind.error, messageArguments, typeName.source, 1455 messageKind.error, messageArguments, typeName.source,
1459 visitor.enclosingElement); 1456 visitor.enclosingElement);
1460 var arguments = new LinkBuilder<DartType>(); 1457 var arguments = new LinkBuilder<DartType>();
1461 resolveTypeArguments(visitor, node, null, arguments); 1458 resolveTypeArguments(visitor, node, null, arguments);
1462 return isAmbiguous 1459 return new MalformedType(erroneousElement,
1463 ? new AmbiguousType(erroneousElement, arguments.toLink())
1464 : new MalformedType(erroneousElement,
1465 userProvidedBadType, arguments.toLink()); 1460 userProvidedBadType, arguments.toLink());
1466 } 1461 }
1467 1462
1468 DartType checkNoTypeArguments(DartType type) { 1463 DartType checkNoTypeArguments(DartType type) {
1469 var arguments = new LinkBuilder<DartType>(); 1464 var arguments = new LinkBuilder<DartType>();
1470 bool hasTypeArgumentMismatch = resolveTypeArguments( 1465 bool hasTypeArgumentMismatch = resolveTypeArguments(
1471 visitor, node, const Link<DartType>(), arguments); 1466 visitor, node, const Link<DartType>(), arguments);
1472 if (hasTypeArgumentMismatch) { 1467 if (hasTypeArgumentMismatch) {
1473 type = new MalformedType( 1468 type = new MalformedType(
1474 new ErroneousElementX(MessageKind.TYPE_ARGUMENT_COUNT_MISMATCH, 1469 new ErroneousElementX(MessageKind.TYPE_ARGUMENT_COUNT_MISMATCH,
1475 {'type': node}, typeName.source, visitor.enclosingElement), 1470 {'type': node}, typeName.source, visitor.enclosingElement),
1476 type, arguments.toLink()); 1471 type, arguments.toLink());
1477 } 1472 }
1478 return type; 1473 return type;
1479 } 1474 }
1480 1475
1481 if (element == null) { 1476 if (element == null) {
1482 type = reportFailureAndCreateType( 1477 type = reportFailureAndCreateType(
1483 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.typeName}, 1478 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.typeName});
1484 isError: malformedIsError);
1485 } else if (element.isAmbiguous()) { 1479 } else if (element.isAmbiguous()) {
1486 AmbiguousElement ambiguous = element; 1480 AmbiguousElement ambiguous = element;
1487 type = reportFailureAndCreateType( 1481 type = reportFailureAndCreateType(
1488 ambiguous.messageKind, ambiguous.messageArguments, 1482 ambiguous.messageKind, ambiguous.messageArguments);
1489 isError: ambiguousIsError, isAmbiguous: true);
1490 ambiguous.diagnose(visitor.mapping.currentElement, compiler); 1483 ambiguous.diagnose(visitor.mapping.currentElement, compiler);
1491 } else if (!element.impliesType()) { 1484 } else if (!element.impliesType()) {
1492 type = reportFailureAndCreateType( 1485 type = reportFailureAndCreateType(
1493 MessageKind.NOT_A_TYPE, {'node': node.typeName}, 1486 MessageKind.NOT_A_TYPE, {'node': node.typeName});
1494 isError: malformedIsError);
1495 } else { 1487 } else {
1496 if (identical(element, compiler.types.voidType.element) || 1488 if (identical(element, compiler.types.voidType.element) ||
1497 identical(element, compiler.dynamicClass)) { 1489 identical(element, compiler.dynamicClass)) {
1498 type = checkNoTypeArguments(element.computeType(compiler)); 1490 type = checkNoTypeArguments(element.computeType(compiler));
1499 } else if (element.isClass()) { 1491 } else if (element.isClass()) {
1500 ClassElement cls = element; 1492 ClassElement cls = element;
1501 compiler.resolver._ensureClassWillBeResolved(cls); 1493 compiler.resolver._ensureClassWillBeResolved(cls);
1502 element.computeType(compiler); 1494 element.computeType(compiler);
1503 var arguments = new LinkBuilder<DartType>(); 1495 var arguments = new LinkBuilder<DartType>();
1504 bool hasTypeArgumentMismatch = resolveTypeArguments( 1496 bool hasTypeArgumentMismatch = resolveTypeArguments(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 bool isInFactoryConstructor = 1530 bool isInFactoryConstructor =
1539 outer != null && outer.isFactoryConstructor(); 1531 outer != null && outer.isFactoryConstructor();
1540 if (!outer.isClass() && 1532 if (!outer.isClass() &&
1541 !outer.isTypedef() && 1533 !outer.isTypedef() &&
1542 !isInFactoryConstructor && 1534 !isInFactoryConstructor &&
1543 Elements.isInStaticContext(visitor.enclosingElement)) { 1535 Elements.isInStaticContext(visitor.enclosingElement)) {
1544 compiler.backend.registerThrowRuntimeError(visitor.mapping); 1536 compiler.backend.registerThrowRuntimeError(visitor.mapping);
1545 type = reportFailureAndCreateType( 1537 type = reportFailureAndCreateType(
1546 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, 1538 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER,
1547 {'typeVariableName': node}, 1539 {'typeVariableName': node},
1548 userProvidedBadType: element.computeType(compiler), 1540 userProvidedBadType: element.computeType(compiler));
1549 isError: malformedIsError);
1550 } else { 1541 } else {
1551 type = element.computeType(compiler); 1542 type = element.computeType(compiler);
1552 } 1543 }
1553 type = checkNoTypeArguments(type); 1544 type = checkNoTypeArguments(type);
1554 } else { 1545 } else {
1555 compiler.cancel("unexpected element kind ${element.kind}", 1546 compiler.cancel("unexpected element kind ${element.kind}",
1556 node: node); 1547 node: node);
1557 } 1548 }
1558 } 1549 }
1559 visitor.useType(node, type); 1550 visitor.useType(node, type);
1560 return type; 1551 return type;
1561 } 1552 }
1562 1553
1563 /** 1554 /**
1564 * Resolves the type arguments of [node] and adds these to [arguments]. 1555 * Resolves the type arguments of [node] and adds these to [arguments].
1565 * 1556 *
1566 * Returns [: true :] if the number of type arguments did not match the 1557 * Returns [: true :] if the number of type arguments did not match the
1567 * number of type variables. 1558 * number of type variables.
1568 */ 1559 */
1569 bool resolveTypeArguments( 1560 bool resolveTypeArguments(
1570 MappingVisitor visitor, 1561 MappingVisitor visitor,
1571 TypeAnnotation node, 1562 TypeAnnotation node,
1572 Link<DartType> typeVariables, 1563 Link<DartType> typeVariables,
1573 LinkBuilder<DartType> arguments, 1564 LinkBuilder<DartType> arguments) {
1574 {bool ambiguousIsError: false}) {
1575 if (node.typeArguments == null) { 1565 if (node.typeArguments == null) {
1576 return false; 1566 return false;
1577 } 1567 }
1578 bool typeArgumentCountMismatch = false; 1568 bool typeArgumentCountMismatch = false;
1579 for (Link<Node> typeArguments = node.typeArguments.nodes; 1569 for (Link<Node> typeArguments = node.typeArguments.nodes;
1580 !typeArguments.isEmpty; 1570 !typeArguments.isEmpty;
1581 typeArguments = typeArguments.tail) { 1571 typeArguments = typeArguments.tail) {
1582 if (typeVariables != null && typeVariables.isEmpty) { 1572 if (typeVariables != null && typeVariables.isEmpty) {
1583 visitor.warning( 1573 visitor.warning(
1584 typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT.warning); 1574 typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT.warning);
1585 typeArgumentCountMismatch = true; 1575 typeArgumentCountMismatch = true;
1586 } 1576 }
1587 DartType argType = resolveTypeAnnotation(visitor, typeArguments.head, 1577 DartType argType = resolveTypeAnnotation(visitor, typeArguments.head);
1588 ambiguousIsError: ambiguousIsError);
1589 arguments.addLast(argType); 1578 arguments.addLast(argType);
1590 if (typeVariables != null && !typeVariables.isEmpty) { 1579 if (typeVariables != null && !typeVariables.isEmpty) {
1591 typeVariables = typeVariables.tail; 1580 typeVariables = typeVariables.tail;
1592 } 1581 }
1593 } 1582 }
1594 if (typeVariables != null && !typeVariables.isEmpty) { 1583 if (typeVariables != null && !typeVariables.isEmpty) {
1595 visitor.warning(node.typeArguments, 1584 visitor.warning(node.typeArguments,
1596 MessageKind.MISSING_TYPE_ARGUMENT.warning); 1585 MessageKind.MISSING_TYPE_ARGUMENT.warning);
1597 typeArgumentCountMismatch = true; 1586 typeArgumentCountMismatch = true;
1598 } 1587 }
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 */ 2668 */
2680 FunctionElement resolveConstructor(NewExpression node) { 2669 FunctionElement resolveConstructor(NewExpression node) {
2681 return node.accept(new ConstructorResolver(compiler, this)); 2670 return node.accept(new ConstructorResolver(compiler, this));
2682 } 2671 }
2683 2672
2684 FunctionElement resolveRedirectingFactory(Return node) { 2673 FunctionElement resolveRedirectingFactory(Return node) {
2685 return node.accept(new ConstructorResolver(compiler, this)); 2674 return node.accept(new ConstructorResolver(compiler, this));
2686 } 2675 }
2687 2676
2688 DartType resolveTypeExpression(TypeAnnotation node) { 2677 DartType resolveTypeExpression(TypeAnnotation node) {
2689 return resolveTypeAnnotation(node, isTypeExpression: true); 2678 return resolveTypeAnnotation(node);
2690 } 2679 }
2691 2680
2692 DartType resolveTypeAnnotation(TypeAnnotation node, 2681 DartType resolveTypeAnnotation(TypeAnnotation node) {
2693 {bool isTypeExpression: false}) { 2682 DartType type = typeResolver.resolveTypeAnnotation(this, node);
2694 DartType type = typeResolver.resolveTypeAnnotation(
2695 this, node, ambiguousIsError: isTypeExpression);
2696 if (type == null) return null; 2683 if (type == null) return null;
2697 if (inCheckContext) { 2684 if (inCheckContext) {
2698 compiler.enqueuer.resolution.registerIsCheck(type, mapping); 2685 compiler.enqueuer.resolution.registerIsCheck(type, mapping);
2699 compiler.backend.registerRequiredType(type, enclosingElement); 2686 compiler.backend.registerRequiredType(type, enclosingElement);
2700 } 2687 }
2701 return type; 2688 return type;
2702 } 2689 }
2703 2690
2704 visitModifiers(Modifiers node) { 2691 visitModifiers(Modifiers node) {
2705 // TODO(ngeoffray): Implement this. 2692 // TODO(ngeoffray): Implement this.
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 return e; 4063 return e;
4077 } 4064 }
4078 4065
4079 /// Assumed to be called by [resolveRedirectingFactory]. 4066 /// Assumed to be called by [resolveRedirectingFactory].
4080 Element visitReturn(Return node) { 4067 Element visitReturn(Return node) {
4081 Node expression = node.expression; 4068 Node expression = node.expression;
4082 return finishConstructorReference(visit(expression), 4069 return finishConstructorReference(visit(expression),
4083 expression, expression); 4070 expression, expression);
4084 } 4071 }
4085 } 4072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698