| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 related_types; | 5 library related_types; |
| 6 | 6 |
| 7 import 'package:compiler/src/commandline_options.dart'; | 7 import 'package:compiler/src/commandline_options.dart'; |
| 8 import 'package:compiler/src/compiler.dart'; | 8 import 'package:compiler/src/compiler.dart'; |
| 9 import 'package:compiler/src/core_types.dart'; | 9 import 'package:compiler/src/core_types.dart'; |
| 10 import 'package:compiler/src/elements/resolution_types.dart'; | 10 import 'package:compiler/src/elements/resolution_types.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 ResolvedAst resolvedAst = member.resolvedAst; | 62 ResolvedAst resolvedAst = member.resolvedAst; |
| 63 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | 63 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
| 64 RelatedTypesChecker relatedTypesChecker = | 64 RelatedTypesChecker relatedTypesChecker = |
| 65 new RelatedTypesChecker(compiler, resolvedAst); | 65 new RelatedTypesChecker(compiler, resolvedAst); |
| 66 compiler.reporter.withCurrentElement(member.implementation, () { | 66 compiler.reporter.withCurrentElement(member.implementation, () { |
| 67 relatedTypesChecker.apply(resolvedAst.node); | 67 relatedTypesChecker.apply(resolvedAst.node); |
| 68 }); | 68 }); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 class RelatedTypesChecker extends TraversalVisitor<DartType, dynamic> { | 72 class RelatedTypesChecker |
| 73 extends TraversalVisitor<ResolutionDartType, dynamic> { |
| 73 final Compiler compiler; | 74 final Compiler compiler; |
| 74 final ResolvedAst resolvedAst; | 75 final ResolvedAst resolvedAst; |
| 75 | 76 |
| 76 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst) | 77 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst) |
| 77 : this.resolvedAst = resolvedAst, | 78 : this.resolvedAst = resolvedAst, |
| 78 super(resolvedAst.elements); | 79 super(resolvedAst.elements); |
| 79 | 80 |
| 80 ClosedWorld get world => compiler.resolverWorld.closedWorldForTesting; | 81 ClosedWorld get world => compiler.resolverWorld.closedWorldForTesting; |
| 81 | 82 |
| 82 CommonElements get commonElements => compiler.commonElements; | 83 CommonElements get commonElements => compiler.commonElements; |
| 83 | 84 |
| 84 DiagnosticReporter get reporter => compiler.reporter; | 85 DiagnosticReporter get reporter => compiler.reporter; |
| 85 | 86 |
| 86 InterfaceType get thisType => resolvedAst.element.enclosingClass.thisType; | 87 ResolutionInterfaceType get thisType => |
| 88 resolvedAst.element.enclosingClass.thisType; |
| 87 | 89 |
| 88 /// Returns `true` if there exists no common subtype of [left] and [right]. | 90 /// Returns `true` if there exists no common subtype of [left] and [right]. |
| 89 bool hasEmptyIntersection(DartType left, DartType right) { | 91 bool hasEmptyIntersection(ResolutionDartType left, ResolutionDartType right) { |
| 90 if (left == right) return false; | 92 if (left == right) return false; |
| 91 if (left == null || right == null) return false; | 93 if (left == null || right == null) return false; |
| 92 ClassElement leftClass = const ClassFinder().findClass(left); | 94 ClassElement leftClass = const ClassFinder().findClass(left); |
| 93 ClassElement rightClass = const ClassFinder().findClass(right); | 95 ClassElement rightClass = const ClassFinder().findClass(right); |
| 94 if (leftClass != null && rightClass != null) { | 96 if (leftClass != null && rightClass != null) { |
| 95 return !world.haveAnyCommonSubtypes(leftClass, rightClass); | 97 return !world.haveAnyCommonSubtypes(leftClass, rightClass); |
| 96 } | 98 } |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| 99 | 101 |
| 100 /// Checks that there exists a common subtype of [left] and [right] or report | 102 /// Checks that there exists a common subtype of [left] and [right] or report |
| 101 /// a hint otherwise. | 103 /// a hint otherwise. |
| 102 void checkRelated(Node node, DartType left, DartType right) { | 104 void checkRelated( |
| 105 Node node, ResolutionDartType left, ResolutionDartType right) { |
| 103 if (hasEmptyIntersection(left, right)) { | 106 if (hasEmptyIntersection(left, right)) { |
| 104 reporter.reportHintMessage( | 107 reporter.reportHintMessage( |
| 105 node, MessageKind.NO_COMMON_SUBTYPES, {'left': left, 'right': right}); | 108 node, MessageKind.NO_COMMON_SUBTYPES, {'left': left, 'right': right}); |
| 106 } | 109 } |
| 107 } | 110 } |
| 108 | 111 |
| 109 /// Check weakly typed collection methods, like `Map.containsKey`, | 112 /// Check weakly typed collection methods, like `Map.containsKey`, |
| 110 /// `Map.containsValue` and `Iterable.contains`. | 113 /// `Map.containsValue` and `Iterable.contains`. |
| 111 void checkDynamicInvoke(Node node, DartType receiverType, | 114 void checkDynamicInvoke(Node node, ResolutionDartType receiverType, |
| 112 List<DartType> argumentTypes, Selector selector) { | 115 List<ResolutionDartType> argumentTypes, Selector selector) { |
| 113 if (selector.name == 'containsKey' && | 116 if (selector.name == 'containsKey' && |
| 114 selector.callStructure == CallStructure.ONE_ARG) { | 117 selector.callStructure == CallStructure.ONE_ARG) { |
| 115 InterfaceType mapType = findMapType(receiverType); | 118 ResolutionInterfaceType mapType = findMapType(receiverType); |
| 116 if (mapType != null) { | 119 if (mapType != null) { |
| 117 DartType keyType = findMapKeyType(mapType); | 120 ResolutionDartType keyType = findMapKeyType(mapType); |
| 118 checkRelated(node, keyType, argumentTypes.first); | 121 checkRelated(node, keyType, argumentTypes.first); |
| 119 } | 122 } |
| 120 } else if (selector.name == 'containsValue' && | 123 } else if (selector.name == 'containsValue' && |
| 121 selector.callStructure == CallStructure.ONE_ARG) { | 124 selector.callStructure == CallStructure.ONE_ARG) { |
| 122 InterfaceType mapType = findMapType(receiverType); | 125 ResolutionInterfaceType mapType = findMapType(receiverType); |
| 123 if (mapType != null) { | 126 if (mapType != null) { |
| 124 DartType valueType = findMapValueType(mapType); | 127 ResolutionDartType valueType = findMapValueType(mapType); |
| 125 checkRelated(node, valueType, argumentTypes.first); | 128 checkRelated(node, valueType, argumentTypes.first); |
| 126 } | 129 } |
| 127 } else if (selector.name == 'contains' && | 130 } else if (selector.name == 'contains' && |
| 128 selector.callStructure == CallStructure.ONE_ARG) { | 131 selector.callStructure == CallStructure.ONE_ARG) { |
| 129 InterfaceType iterableType = findIterableType(receiverType); | 132 ResolutionInterfaceType iterableType = findIterableType(receiverType); |
| 130 if (iterableType != null) { | 133 if (iterableType != null) { |
| 131 DartType elementType = findIterableElementType(iterableType); | 134 ResolutionDartType elementType = findIterableElementType(iterableType); |
| 132 checkRelated(node, elementType, argumentTypes.first); | 135 checkRelated(node, elementType, argumentTypes.first); |
| 133 } | 136 } |
| 134 } else if (selector.name == 'remove' && | 137 } else if (selector.name == 'remove' && |
| 135 selector.callStructure == CallStructure.ONE_ARG) { | 138 selector.callStructure == CallStructure.ONE_ARG) { |
| 136 InterfaceType mapType = findMapType(receiverType); | 139 ResolutionInterfaceType mapType = findMapType(receiverType); |
| 137 if (mapType != null) { | 140 if (mapType != null) { |
| 138 DartType keyType = findMapKeyType(mapType); | 141 ResolutionDartType keyType = findMapKeyType(mapType); |
| 139 checkRelated(node, keyType, argumentTypes.first); | 142 checkRelated(node, keyType, argumentTypes.first); |
| 140 } | 143 } |
| 141 InterfaceType listType = findListType(receiverType); | 144 ResolutionInterfaceType listType = findListType(receiverType); |
| 142 if (listType != null) { | 145 if (listType != null) { |
| 143 DartType valueType = findListElementType(listType); | 146 ResolutionDartType valueType = findListElementType(listType); |
| 144 checkRelated(node, valueType, argumentTypes.first); | 147 checkRelated(node, valueType, argumentTypes.first); |
| 145 } | 148 } |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 | 151 |
| 149 /// Return the interface type implemented by [type] or `null` if no interface | 152 /// Return the interface type implemented by [type] or `null` if no interface |
| 150 /// type is implied by [type]. | 153 /// type is implied by [type]. |
| 151 InterfaceType findInterfaceType(DartType type) { | 154 ResolutionInterfaceType findInterfaceType(ResolutionDartType type) { |
| 152 return Types.computeInterfaceType(compiler.resolution, type); | 155 return Types.computeInterfaceType(compiler.resolution, type); |
| 153 } | 156 } |
| 154 | 157 |
| 155 /// Returns the supertype of [receiver] that implements [cls], if any. | 158 /// Returns the supertype of [receiver] that implements [cls], if any. |
| 156 InterfaceType findClassType(DartType receiver, ClassElement cls) { | 159 ResolutionInterfaceType findClassType( |
| 157 InterfaceType interfaceType = findInterfaceType(receiver); | 160 ResolutionDartType receiver, ClassElement cls) { |
| 161 ResolutionInterfaceType interfaceType = findInterfaceType(receiver); |
| 158 if (interfaceType == null) return null; | 162 if (interfaceType == null) return null; |
| 159 InterfaceType mapType = interfaceType.asInstanceOf(cls); | 163 ResolutionInterfaceType mapType = interfaceType.asInstanceOf(cls); |
| 160 if (mapType == null) return null; | 164 if (mapType == null) return null; |
| 161 return mapType; | 165 return mapType; |
| 162 } | 166 } |
| 163 | 167 |
| 164 /// Returns the supertype of [receiver] that implements `Iterable`, if any. | 168 /// Returns the supertype of [receiver] that implements `Iterable`, if any. |
| 165 InterfaceType findIterableType(DartType receiver) { | 169 ResolutionInterfaceType findIterableType(ResolutionDartType receiver) { |
| 166 return findClassType(receiver, commonElements.iterableClass); | 170 return findClassType(receiver, commonElements.iterableClass); |
| 167 } | 171 } |
| 168 | 172 |
| 169 /// Returns the element type of the supertype of [receiver] that implements | 173 /// Returns the element type of the supertype of [receiver] that implements |
| 170 /// `Iterable`, if any. | 174 /// `Iterable`, if any. |
| 171 DartType findIterableElementType(InterfaceType iterableType) { | 175 ResolutionDartType findIterableElementType( |
| 176 ResolutionInterfaceType iterableType) { |
| 172 if (iterableType == null) return null; | 177 if (iterableType == null) return null; |
| 173 return iterableType.typeArguments[0]; | 178 return iterableType.typeArguments[0]; |
| 174 } | 179 } |
| 175 | 180 |
| 176 /// Returns the supertype of [receiver] that implements `Map`, if any. | 181 /// Returns the supertype of [receiver] that implements `Map`, if any. |
| 177 InterfaceType findMapType(DartType receiver) { | 182 ResolutionInterfaceType findMapType(ResolutionDartType receiver) { |
| 178 return findClassType(receiver, commonElements.mapClass); | 183 return findClassType(receiver, commonElements.mapClass); |
| 179 } | 184 } |
| 180 | 185 |
| 181 /// Returns the key type of the supertype of [receiver] that implements | 186 /// Returns the key type of the supertype of [receiver] that implements |
| 182 /// `Map`, if any. | 187 /// `Map`, if any. |
| 183 DartType findMapKeyType(InterfaceType mapType) { | 188 ResolutionDartType findMapKeyType(ResolutionInterfaceType mapType) { |
| 184 if (mapType == null) return null; | 189 if (mapType == null) return null; |
| 185 return mapType.typeArguments[0]; | 190 return mapType.typeArguments[0]; |
| 186 } | 191 } |
| 187 | 192 |
| 188 /// Returns the value type of the supertype of [receiver] that implements | 193 /// Returns the value type of the supertype of [receiver] that implements |
| 189 /// `Map`, if any. | 194 /// `Map`, if any. |
| 190 DartType findMapValueType(InterfaceType mapType) { | 195 ResolutionDartType findMapValueType(ResolutionInterfaceType mapType) { |
| 191 if (mapType == null) return null; | 196 if (mapType == null) return null; |
| 192 return mapType.typeArguments[1]; | 197 return mapType.typeArguments[1]; |
| 193 } | 198 } |
| 194 | 199 |
| 195 /// Returns the supertype of [receiver] that implements `List`, if any. | 200 /// Returns the supertype of [receiver] that implements `List`, if any. |
| 196 InterfaceType findListType(DartType receiver) { | 201 ResolutionInterfaceType findListType(ResolutionDartType receiver) { |
| 197 return findClassType(receiver, commonElements.listClass); | 202 return findClassType(receiver, commonElements.listClass); |
| 198 } | 203 } |
| 199 | 204 |
| 200 /// Returns the element type of the supertype of [receiver] that implements | 205 /// Returns the element type of the supertype of [receiver] that implements |
| 201 /// `List`, if any. | 206 /// `List`, if any. |
| 202 DartType findListElementType(InterfaceType listType) { | 207 ResolutionDartType findListElementType(ResolutionInterfaceType listType) { |
| 203 if (listType == null) return null; | 208 if (listType == null) return null; |
| 204 return listType.typeArguments[0]; | 209 return listType.typeArguments[0]; |
| 205 } | 210 } |
| 206 | 211 |
| 207 /// Returns the implied return type of [type] or `dynamic` if no return type | 212 /// Returns the implied return type of [type] or `dynamic` if no return type |
| 208 /// is implied. | 213 /// is implied. |
| 209 DartType findReturnType(DartType type) { | 214 ResolutionDartType findReturnType(ResolutionDartType type) { |
| 210 if (type is FunctionType) { | 215 if (type is ResolutionFunctionType) { |
| 211 return type.returnType; | 216 return type.returnType; |
| 212 } | 217 } |
| 213 return const DynamicType(); | 218 return const ResolutionDynamicType(); |
| 214 } | 219 } |
| 215 | 220 |
| 216 /// Visits [arguments] and returns the list of their corresponding types. | 221 /// Visits [arguments] and returns the list of their corresponding types. |
| 217 List<DartType> findArgumentTypes(NodeList arguments) { | 222 List<ResolutionDartType> findArgumentTypes(NodeList arguments) { |
| 218 List<DartType> argumentTypes = <DartType>[]; | 223 List<ResolutionDartType> argumentTypes = <ResolutionDartType>[]; |
| 219 for (Node argument in arguments) { | 224 for (Node argument in arguments) { |
| 220 argumentTypes.add(apply(argument)); | 225 argumentTypes.add(apply(argument)); |
| 221 } | 226 } |
| 222 return argumentTypes; | 227 return argumentTypes; |
| 223 } | 228 } |
| 224 | 229 |
| 225 /// Finds the [MemberSignature] of the [name] property on [type], if any. | 230 /// Finds the [MemberSignature] of the [name] property on [type], if any. |
| 226 MemberSignature lookupInterfaceMember(DartType type, Name name) { | 231 MemberSignature lookupInterfaceMember(ResolutionDartType type, Name name) { |
| 227 InterfaceType interfaceType = findInterfaceType(type); | 232 ResolutionInterfaceType interfaceType = findInterfaceType(type); |
| 228 if (interfaceType == null) return null; | 233 if (interfaceType == null) return null; |
| 229 return interfaceType.lookupInterfaceMember(name); | 234 return interfaceType.lookupInterfaceMember(name); |
| 230 } | 235 } |
| 231 | 236 |
| 232 /// Returns the type of an access of the [name] property on [type], or | 237 /// Returns the type of an access of the [name] property on [type], or |
| 233 /// `dynamic` if no property was found. | 238 /// `dynamic` if no property was found. |
| 234 DartType lookupInterfaceMemberAccessType(DartType type, Name name) { | 239 ResolutionDartType lookupInterfaceMemberAccessType( |
| 240 ResolutionDartType type, Name name) { |
| 235 MemberSignature member = lookupInterfaceMember(type, name); | 241 MemberSignature member = lookupInterfaceMember(type, name); |
| 236 if (member == null) return const DynamicType(); | 242 if (member == null) return const ResolutionDynamicType(); |
| 237 return member.type; | 243 return member.type; |
| 238 } | 244 } |
| 239 | 245 |
| 240 /// Returns the function type of the [name] property on [type], or | 246 /// Returns the function type of the [name] property on [type], or |
| 241 /// `dynamic` if no property was found. | 247 /// `dynamic` if no property was found. |
| 242 FunctionType lookupInterfaceMemberInvocationType(DartType type, Name name) { | 248 ResolutionFunctionType lookupInterfaceMemberInvocationType( |
| 249 ResolutionDartType type, Name name) { |
| 243 MemberSignature member = lookupInterfaceMember(type, name); | 250 MemberSignature member = lookupInterfaceMember(type, name); |
| 244 if (member == null) return null; | 251 if (member == null) return null; |
| 245 return member.functionType; | 252 return member.functionType; |
| 246 } | 253 } |
| 247 | 254 |
| 248 DartType apply(Node node, [_]) { | 255 ResolutionDartType apply(Node node, [_]) { |
| 249 DartType type = node.accept(this); | 256 ResolutionDartType type = node.accept(this); |
| 250 if (type == null) { | 257 if (type == null) { |
| 251 type = const DynamicType(); | 258 type = const ResolutionDynamicType(); |
| 252 } | 259 } |
| 253 return type; | 260 return type; |
| 254 } | 261 } |
| 255 | 262 |
| 256 @override | 263 @override |
| 257 DartType visitEquals(Send node, Node left, Node right, _) { | 264 ResolutionDartType visitEquals(Send node, Node left, Node right, _) { |
| 258 DartType leftType = apply(left); | 265 ResolutionDartType leftType = apply(left); |
| 259 DartType rightType = apply(right); | 266 ResolutionDartType rightType = apply(right); |
| 260 checkRelated(node, leftType, rightType); | 267 checkRelated(node, leftType, rightType); |
| 261 return commonElements.boolType; | 268 return commonElements.boolType; |
| 262 } | 269 } |
| 263 | 270 |
| 264 @override | 271 @override |
| 265 DartType visitNotEquals(Send node, Node left, Node right, _) { | 272 ResolutionDartType visitNotEquals(Send node, Node left, Node right, _) { |
| 266 DartType leftType = apply(left); | 273 ResolutionDartType leftType = apply(left); |
| 267 DartType rightType = apply(right); | 274 ResolutionDartType rightType = apply(right); |
| 268 checkRelated(node, leftType, rightType); | 275 checkRelated(node, leftType, rightType); |
| 269 return commonElements.boolType; | 276 return commonElements.boolType; |
| 270 } | 277 } |
| 271 | 278 |
| 272 @override | 279 @override |
| 273 DartType visitIndex(Send node, Node receiver, Node index, _) { | 280 ResolutionDartType visitIndex(Send node, Node receiver, Node index, _) { |
| 274 DartType receiverType = apply(receiver); | 281 ResolutionDartType receiverType = apply(receiver); |
| 275 DartType indexType = apply(index); | 282 ResolutionDartType indexType = apply(index); |
| 276 InterfaceType mapType = findMapType(receiverType); | 283 ResolutionInterfaceType mapType = findMapType(receiverType); |
| 277 DartType keyType = findMapKeyType(mapType); | 284 ResolutionDartType keyType = findMapKeyType(mapType); |
| 278 DartType valueType = findMapValueType(mapType); | 285 ResolutionDartType valueType = findMapValueType(mapType); |
| 279 checkRelated(index, keyType, indexType); | 286 checkRelated(index, keyType, indexType); |
| 280 return valueType; | 287 return valueType; |
| 281 } | 288 } |
| 282 | 289 |
| 283 @override | 290 @override |
| 284 DartType visitLiteralInt(LiteralInt node) { | 291 ResolutionDartType visitLiteralInt(LiteralInt node) { |
| 285 return commonElements.intType; | 292 return commonElements.intType; |
| 286 } | 293 } |
| 287 | 294 |
| 288 @override | 295 @override |
| 289 DartType visitLiteralString(LiteralString node) { | 296 ResolutionDartType visitLiteralString(LiteralString node) { |
| 290 return commonElements.stringType; | 297 return commonElements.stringType; |
| 291 } | 298 } |
| 292 | 299 |
| 293 @override | 300 @override |
| 294 DartType visitLiteralBool(LiteralBool node) { | 301 ResolutionDartType visitLiteralBool(LiteralBool node) { |
| 295 return commonElements.boolType; | 302 return commonElements.boolType; |
| 296 } | 303 } |
| 297 | 304 |
| 298 @override | 305 @override |
| 299 DartType visitLiteralMap(LiteralMap node) { | 306 ResolutionDartType visitLiteralMap(LiteralMap node) { |
| 300 return elements.getType(node); | 307 return elements.getType(node); |
| 301 } | 308 } |
| 302 | 309 |
| 303 @override | 310 @override |
| 304 DartType visitLiteralList(LiteralList node) { | 311 ResolutionDartType visitLiteralList(LiteralList node) { |
| 305 return elements.getType(node); | 312 return elements.getType(node); |
| 306 } | 313 } |
| 307 | 314 |
| 308 @override | 315 @override |
| 309 DartType visitLiteralNull(LiteralNull node) { | 316 ResolutionDartType visitLiteralNull(LiteralNull node) { |
| 310 return elements.getType(node); | 317 return elements.getType(node); |
| 311 } | 318 } |
| 312 | 319 |
| 313 @override | 320 @override |
| 314 DartType visitLocalVariableGet(Send node, LocalVariableElement variable, _) { | 321 ResolutionDartType visitLocalVariableGet( |
| 322 Send node, LocalVariableElement variable, _) { |
| 315 return variable.type; | 323 return variable.type; |
| 316 } | 324 } |
| 317 | 325 |
| 318 @override | 326 @override |
| 319 DartType visitLocalFunctionGet(Send node, LocalFunctionElement function, _) { | 327 ResolutionDartType visitLocalFunctionGet( |
| 328 Send node, LocalFunctionElement function, _) { |
| 320 return function.type; | 329 return function.type; |
| 321 } | 330 } |
| 322 | 331 |
| 323 @override | 332 @override |
| 324 DartType visitParameterGet(Send node, ParameterElement parameter, _) { | 333 ResolutionDartType visitParameterGet( |
| 334 Send node, ParameterElement parameter, _) { |
| 325 return parameter.type; | 335 return parameter.type; |
| 326 } | 336 } |
| 327 | 337 |
| 328 @override | 338 @override |
| 329 DartType visitThisPropertyGet(Send node, Name name, _) { | 339 ResolutionDartType visitThisPropertyGet(Send node, Name name, _) { |
| 330 return lookupInterfaceMemberAccessType(thisType, name); | 340 return lookupInterfaceMemberAccessType(thisType, name); |
| 331 } | 341 } |
| 332 | 342 |
| 333 @override | 343 @override |
| 334 DartType visitDynamicPropertyGet(Send node, Node receiver, Name name, _) { | 344 ResolutionDartType visitDynamicPropertyGet( |
| 335 DartType receiverType = apply(receiver); | 345 Send node, Node receiver, Name name, _) { |
| 346 ResolutionDartType receiverType = apply(receiver); |
| 336 return lookupInterfaceMemberAccessType(receiverType, name); | 347 return lookupInterfaceMemberAccessType(receiverType, name); |
| 337 } | 348 } |
| 338 | 349 |
| 339 @override | 350 @override |
| 340 DartType visitIfNotNullDynamicPropertyGet( | 351 ResolutionDartType visitIfNotNullDynamicPropertyGet( |
| 341 Send node, Node receiver, Name name, _) { | 352 Send node, Node receiver, Name name, _) { |
| 342 DartType receiverType = apply(receiver); | 353 ResolutionDartType receiverType = apply(receiver); |
| 343 return lookupInterfaceMemberAccessType(receiverType, name); | 354 return lookupInterfaceMemberAccessType(receiverType, name); |
| 344 } | 355 } |
| 345 | 356 |
| 346 @override | 357 @override |
| 347 DartType visitStaticFieldGet(Send node, FieldElement field, _) { | 358 ResolutionDartType visitStaticFieldGet(Send node, FieldElement field, _) { |
| 348 return field.type; | 359 return field.type; |
| 349 } | 360 } |
| 350 | 361 |
| 351 @override | 362 @override |
| 352 DartType visitTopLevelFieldGet(Send node, FieldElement field, _) { | 363 ResolutionDartType visitTopLevelFieldGet(Send node, FieldElement field, _) { |
| 353 return field.type; | 364 return field.type; |
| 354 } | 365 } |
| 355 | 366 |
| 356 @override | 367 @override |
| 357 DartType visitDynamicPropertyInvoke( | 368 ResolutionDartType visitDynamicPropertyInvoke( |
| 358 Send node, Node receiver, NodeList arguments, Selector selector, _) { | 369 Send node, Node receiver, NodeList arguments, Selector selector, _) { |
| 359 DartType receiverType = apply(receiver); | 370 ResolutionDartType receiverType = apply(receiver); |
| 360 List<DartType> argumentTypes = findArgumentTypes(arguments); | 371 List<ResolutionDartType> argumentTypes = findArgumentTypes(arguments); |
| 361 FunctionType methodType = | 372 ResolutionFunctionType methodType = |
| 362 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); | 373 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); |
| 363 checkDynamicInvoke(node, receiverType, argumentTypes, selector); | 374 checkDynamicInvoke(node, receiverType, argumentTypes, selector); |
| 364 return findReturnType(methodType); | 375 return findReturnType(methodType); |
| 365 } | 376 } |
| 366 | 377 |
| 367 @override | 378 @override |
| 368 DartType visitThisPropertyInvoke( | 379 ResolutionDartType visitThisPropertyInvoke( |
| 369 Send node, NodeList arguments, Selector selector, _) { | 380 Send node, NodeList arguments, Selector selector, _) { |
| 370 DartType receiverType = thisType; | 381 ResolutionDartType receiverType = thisType; |
| 371 List<DartType> argumentTypes = findArgumentTypes(arguments); | 382 List<ResolutionDartType> argumentTypes = findArgumentTypes(arguments); |
| 372 FunctionType methodType = | 383 ResolutionFunctionType methodType = |
| 373 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); | 384 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); |
| 374 checkDynamicInvoke(node, receiverType, argumentTypes, selector); | 385 checkDynamicInvoke(node, receiverType, argumentTypes, selector); |
| 375 return findReturnType(methodType); | 386 return findReturnType(methodType); |
| 376 } | 387 } |
| 377 | 388 |
| 378 @override | 389 @override |
| 379 DartType visitIfNotNullDynamicPropertyInvoke( | 390 ResolutionDartType visitIfNotNullDynamicPropertyInvoke( |
| 380 Send node, Node receiver, NodeList arguments, Selector selector, _) { | 391 Send node, Node receiver, NodeList arguments, Selector selector, _) { |
| 381 DartType receiverType = apply(receiver); | 392 ResolutionDartType receiverType = apply(receiver); |
| 382 List<DartType> argumentTypes = findArgumentTypes(arguments); | 393 List<ResolutionDartType> argumentTypes = findArgumentTypes(arguments); |
| 383 FunctionType methodType = | 394 ResolutionFunctionType methodType = |
| 384 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); | 395 lookupInterfaceMemberInvocationType(receiverType, selector.memberName); |
| 385 checkDynamicInvoke(node, receiverType, argumentTypes, selector); | 396 checkDynamicInvoke(node, receiverType, argumentTypes, selector); |
| 386 return findReturnType(methodType); | 397 return findReturnType(methodType); |
| 387 } | 398 } |
| 388 | 399 |
| 389 @override | 400 @override |
| 390 DartType visitTopLevelFunctionInvoke(Send node, MethodElement function, | 401 ResolutionDartType visitTopLevelFunctionInvoke( |
| 391 NodeList arguments, CallStructure callStructure, _) { | 402 Send node, |
| 403 MethodElement function, |
| 404 NodeList arguments, |
| 405 CallStructure callStructure, |
| 406 _) { |
| 392 apply(arguments); | 407 apply(arguments); |
| 393 return findReturnType(function.type); | 408 return findReturnType(function.type); |
| 394 } | 409 } |
| 395 | 410 |
| 396 @override | 411 @override |
| 397 DartType visitStaticFunctionInvoke(Send node, MethodElement function, | 412 ResolutionDartType visitStaticFunctionInvoke( |
| 398 NodeList arguments, CallStructure callStructure, _) { | 413 Send node, |
| 414 MethodElement function, |
| 415 NodeList arguments, |
| 416 CallStructure callStructure, |
| 417 _) { |
| 399 apply(arguments); | 418 apply(arguments); |
| 400 return findReturnType(function.type); | 419 return findReturnType(function.type); |
| 401 } | 420 } |
| 402 } | 421 } |
| 403 | 422 |
| 404 /// Computes the [ClassElement] implied by a type. | 423 /// Computes the [ClassElement] implied by a type. |
| 405 // TODO(johnniwinther): Handle type variables, function types and typedefs. | 424 // TODO(johnniwinther): Handle type variables, function types and typedefs. |
| 406 class ClassFinder extends BaseDartTypeVisitor<ClassElement, dynamic> { | 425 class ClassFinder extends BaseDartTypeVisitor<ClassElement, dynamic> { |
| 407 const ClassFinder(); | 426 const ClassFinder(); |
| 408 | 427 |
| 409 ClassElement findClass(DartType type) => type.accept(this, null); | 428 ClassElement findClass(ResolutionDartType type) => type.accept(this, null); |
| 410 | 429 |
| 411 @override | 430 @override |
| 412 ClassElement visitType(DartType type, _) => null; | 431 ClassElement visitType(ResolutionDartType type, _) => null; |
| 413 | 432 |
| 414 @override | 433 @override |
| 415 ClassElement visitInterfaceType(InterfaceType type, _) { | 434 ClassElement visitInterfaceType(ResolutionInterfaceType type, _) { |
| 416 return type.element; | 435 return type.element; |
| 417 } | 436 } |
| 418 } | 437 } |
| OLD | NEW |