| OLD | NEW |
| 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 library dart2js.typechecker; | 5 library dart2js.typechecker; |
| 6 | 6 |
| 7 import 'common.dart'; | 7 import 'common.dart'; |
| 8 import 'common/names.dart' show | 8 import 'common/names.dart' show |
| 9 Identifiers; | 9 Identifiers; |
| 10 import 'common/resolution.dart' show | 10 import 'common/resolution.dart' show |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 DartType unaliasedBound, InterfaceType interface) { | 749 DartType unaliasedBound, InterfaceType interface) { |
| 750 MemberSignature member = lookupMemberSignature(memberName, interface); | 750 MemberSignature member = lookupMemberSignature(memberName, interface); |
| 751 if (member != null) { | 751 if (member != null) { |
| 752 return new MemberAccess(member); | 752 return new MemberAccess(member); |
| 753 } | 753 } |
| 754 if (name == const PublicName('call')) { | 754 if (name == const PublicName('call')) { |
| 755 if (unaliasedBound.isFunctionType) { | 755 if (unaliasedBound.isFunctionType) { |
| 756 // This is an access the implicit 'call' method of a function type. | 756 // This is an access the implicit 'call' method of a function type. |
| 757 return new FunctionCallAccess(receiverElement, unaliasedBound); | 757 return new FunctionCallAccess(receiverElement, unaliasedBound); |
| 758 } | 758 } |
| 759 if (types.isSubtype(interface, compiler.functionClass.rawType)) { | 759 if (types.isSubtype(interface, coreTypes.functionType)) { |
| 760 // This is an access of the special 'call' method implicitly defined | 760 // This is an access of the special 'call' method implicitly defined |
| 761 // on 'Function'. This method can be called with any arguments, which | 761 // on 'Function'. This method can be called with any arguments, which |
| 762 // we ensure by giving it the type 'dynamic'. | 762 // we ensure by giving it the type 'dynamic'. |
| 763 return new FunctionCallAccess(null, const DynamicType()); | 763 return new FunctionCallAccess(null, const DynamicType()); |
| 764 } | 764 } |
| 765 } | 765 } |
| 766 return null; | 766 return null; |
| 767 } | 767 } |
| 768 | 768 |
| 769 DartType unaliasedBound = | 769 DartType unaliasedBound = |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 message: 'Unexpected operator $name')); | 1327 message: 'Unexpected operator $name')); |
| 1328 | 1328 |
| 1329 // TODO(karlklose): handle `void` in expression context by calling | 1329 // TODO(karlklose): handle `void` in expression context by calling |
| 1330 // [analyzeNonVoid] instead of [analyze]. | 1330 // [analyzeNonVoid] instead of [analyze]. |
| 1331 ElementAccess access = receiverType.isVoid ? const DynamicAccess() | 1331 ElementAccess access = receiverType.isVoid ? const DynamicAccess() |
| 1332 : lookupMember(node, receiverType, operatorName, | 1332 : lookupMember(node, receiverType, operatorName, |
| 1333 MemberKind.OPERATOR, null); | 1333 MemberKind.OPERATOR, null); |
| 1334 LinkBuilder<DartType> argumentTypesBuilder = new LinkBuilder<DartType>(); | 1334 LinkBuilder<DartType> argumentTypesBuilder = new LinkBuilder<DartType>(); |
| 1335 DartType resultType = | 1335 DartType resultType = |
| 1336 analyzeInvocation(node, access, argumentTypesBuilder); | 1336 analyzeInvocation(node, access, argumentTypesBuilder); |
| 1337 if (identical(receiverType.element, compiler.intClass)) { | 1337 if (receiverType == intType) { |
| 1338 if (identical(name, '+') || | 1338 if (identical(name, '+') || |
| 1339 identical(operatorName, '-') || | 1339 identical(operatorName, '-') || |
| 1340 identical(name, '*') || | 1340 identical(name, '*') || |
| 1341 identical(name, '%')) { | 1341 identical(name, '%')) { |
| 1342 DartType argumentType = argumentTypesBuilder.toLink().head; | 1342 DartType argumentType = argumentTypesBuilder.toLink().head; |
| 1343 if (identical(argumentType.element, compiler.intClass)) { | 1343 if (argumentType == intType) { |
| 1344 return intType; | 1344 return intType; |
| 1345 } else if (identical(argumentType.element, compiler.doubleClass)) { | 1345 } else if (argumentType == doubleType) { |
| 1346 return doubleType; | 1346 return doubleType; |
| 1347 } | 1347 } |
| 1348 } | 1348 } |
| 1349 } | 1349 } |
| 1350 return resultType; | 1350 return resultType; |
| 1351 } else if (node.isPropertyAccess) { | 1351 } else if (node.isPropertyAccess) { |
| 1352 ElementAccess access = | 1352 ElementAccess access = |
| 1353 computeAccess(node, selector.source, element, MemberKind.GETTER); | 1353 computeAccess(node, selector.source, element, MemberKind.GETTER); |
| 1354 return access.computeType(resolution); | 1354 return access.computeType(resolution); |
| 1355 } else if (node.isFunctionObjectInvocation) { | 1355 } else if (node.isFunctionObjectInvocation) { |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 if (!types.isAssignable(expressionType, streamOfDynamic)) { | 1832 if (!types.isAssignable(expressionType, streamOfDynamic)) { |
| 1833 reportMessage(node.expression, | 1833 reportMessage(node.expression, |
| 1834 MessageKind.NOT_ASSIGNABLE, | 1834 MessageKind.NOT_ASSIGNABLE, |
| 1835 {'fromType': expressionType, 'toType': streamOfDynamic}, | 1835 {'fromType': expressionType, 'toType': streamOfDynamic}, |
| 1836 isHint: true); | 1836 isHint: true); |
| 1837 } else { | 1837 } else { |
| 1838 InterfaceType interfaceType = | 1838 InterfaceType interfaceType = |
| 1839 Types.computeInterfaceType(resolution, expressionType); | 1839 Types.computeInterfaceType(resolution, expressionType); |
| 1840 if (interfaceType != null) { | 1840 if (interfaceType != null) { |
| 1841 InterfaceType streamType = | 1841 InterfaceType streamType = |
| 1842 interfaceType.asInstanceOf(compiler.streamClass); | 1842 interfaceType.asInstanceOf(streamOfDynamic.element); |
| 1843 if (streamType != null) { | 1843 if (streamType != null) { |
| 1844 DartType streamElementType = streamType.typeArguments.first; | 1844 DartType streamElementType = streamType.typeArguments.first; |
| 1845 if (!types.isAssignable(streamElementType, elementType)) { | 1845 if (!types.isAssignable(streamElementType, elementType)) { |
| 1846 reportMessage(node.expression, | 1846 reportMessage(node.expression, |
| 1847 MessageKind.FORIN_NOT_ASSIGNABLE, | 1847 MessageKind.FORIN_NOT_ASSIGNABLE, |
| 1848 {'currentType': streamElementType, | 1848 {'currentType': streamElementType, |
| 1849 'expressionType': expressionType, | 1849 'expressionType': expressionType, |
| 1850 'elementType': elementType}, | 1850 'elementType': elementType}, |
| 1851 isHint: true); | 1851 isHint: true); |
| 1852 } | 1852 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 | 1996 |
| 1997 visitTypedef(Typedef node) { | 1997 visitTypedef(Typedef node) { |
| 1998 // Do not typecheck [Typedef] nodes. | 1998 // Do not typecheck [Typedef] nodes. |
| 1999 } | 1999 } |
| 2000 | 2000 |
| 2001 visitNode(Node node) { | 2001 visitNode(Node node) { |
| 2002 reporter.internalError(node, | 2002 reporter.internalError(node, |
| 2003 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2003 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
| 2004 } | 2004 } |
| 2005 } | 2005 } |
| OLD | NEW |