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

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

Issue 48383003: Support checking of malbounded types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 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 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 compiler.cancel("unexpected element kind ${element.kind}", 1772 compiler.cancel("unexpected element kind ${element.kind}",
1773 node: node); 1773 node: node);
1774 } 1774 }
1775 // TODO(johnniwinther): We should not resolve type annotations after the 1775 // TODO(johnniwinther): We should not resolve type annotations after the
1776 // resolution queue has been closed. Currently the dart backend does so. 1776 // resolution queue has been closed. Currently the dart backend does so.
1777 // Remove the guarded when this is fixed. 1777 // Remove the guarded when this is fixed.
1778 if (!compiler.enqueuer.resolution.queueIsClosed && 1778 if (!compiler.enqueuer.resolution.queueIsClosed &&
1779 addTypeVariableBoundsCheck) { 1779 addTypeVariableBoundsCheck) {
1780 visitor.addDeferredAction( 1780 visitor.addDeferredAction(
1781 visitor.enclosingElement, 1781 visitor.enclosingElement,
1782 () => checkTypeVariableBounds(node, type)); 1782 () => checkTypeVariableBounds(visitor.mapping, node, type));
1783 } 1783 }
1784 } 1784 }
1785 visitor.useType(node, type); 1785 visitor.useType(node, type);
1786 return type; 1786 return type;
1787 } 1787 }
1788 1788
1789 /// Checks the type arguments of [type] against the type variable bounds. 1789 /// Checks the type arguments of [type] against the type variable bounds.
1790 void checkTypeVariableBounds(TypeAnnotation node, GenericType type) { 1790 void checkTypeVariableBounds(TreeElements elements,
1791 TypeDeclarationElement element = type.element; 1791 TypeAnnotation node, GenericType type) {
1792 Link<DartType> typeArguments = type.typeArguments; 1792 void checkTypeVariableBound(_, DartType typeArgument,
1793 Link<DartType> typeVariables = element.typeVariables; 1793 TypeVariableType typeVariable,
1794 while (!typeVariables.isEmpty && !typeArguments.isEmpty) { 1794 DartType bound) {
1795 TypeVariableType typeVariable = typeVariables.head; 1795 compiler.backend.registerTypeVariableBoundCheck(elements);
1796 DartType bound = typeVariable.element.bound.subst(
1797 type.typeArguments, element.typeVariables);
1798 DartType typeArgument = typeArguments.head;
1799 if (!compiler.types.isSubtype(typeArgument, bound)) { 1796 if (!compiler.types.isSubtype(typeArgument, bound)) {
1800 compiler.reportWarningCode(node, 1797 compiler.reportWarningCode(node,
1801 MessageKind.INVALID_TYPE_VARIABLE_BOUND, 1798 MessageKind.INVALID_TYPE_VARIABLE_BOUND,
1802 {'typeVariable': typeVariable, 1799 {'typeVariable': typeVariable,
1803 'bound': bound, 1800 'bound': bound,
1804 'typeArgument': typeArgument, 1801 'typeArgument': typeArgument,
1805 'thisType': element.thisType}); 1802 'thisType': type.element.thisType});
1806 } 1803 }
1807 typeVariables = typeVariables.tail; 1804 };
1808 typeArguments = typeArguments.tail; 1805
1809 } 1806 compiler.types.checkTypeVariableBounds(type, checkTypeVariableBound);
1810 } 1807 }
1811 1808
1812 /** 1809 /**
1813 * Resolves the type arguments of [node] and adds these to [arguments]. 1810 * Resolves the type arguments of [node] and adds these to [arguments].
1814 * 1811 *
1815 * Returns [: true :] if the number of type arguments did not match the 1812 * Returns [: true :] if the number of type arguments did not match the
1816 * number of type variables. 1813 * number of type variables.
1817 */ 1814 */
1818 bool resolveTypeArguments( 1815 bool resolveTypeArguments(
1819 MappingVisitor visitor, 1816 MappingVisitor visitor,
(...skipping 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after
4681 return finishConstructorReference(visit(expression), 4678 return finishConstructorReference(visit(expression),
4682 expression, expression); 4679 expression, expression);
4683 } 4680 }
4684 } 4681 }
4685 4682
4686 /// Looks up [name] in [scope] and unwraps the result. 4683 /// Looks up [name] in [scope] and unwraps the result.
4687 Element lookupInScope(Compiler compiler, Node node, 4684 Element lookupInScope(Compiler compiler, Node node,
4688 Scope scope, String name) { 4685 Scope scope, String name) {
4689 return Elements.unwrap(scope.lookup(name), compiler, node); 4686 return Elements.unwrap(scope.lookup(name), compiler, node);
4690 } 4687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698