Changeset 1741
- Timestamp:
- 11/07/08 19:55:56 (2 months ago)
- Files:
-
- 1 modified
-
cobra/trunk/Source/Expr.cobra (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Source/Expr.cobra
r1740 r1741 199 199 sugg = '' 200 200 return sugg 201 202 def whoseTypeIsMessage as String 203 """ 204 Returns a suffix for member-not-found error messages. 205 Returns ' whose type is "[.receiverType.name]"' 206 Overridden by IdentifierExpr to return '' when accessing types. 207 """ 208 return ' whose type is "[.receiverType.name]"' 209 210 def throwCannotFindMemberError(receiverExpr as Expr, memberName as String) 211 __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 1) 212 213 def recordCannotFindMemberError(receiverExpr as Expr, memberName as String) 214 __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 2) 215 216 def __throwOrRecordCannotFindMemberError(receiverExpr as Expr, memberName as String, throwOrRecord as int) is nonvirtual 217 require throwOrRecord in [1, 2] 218 suggs = _suggestionsMessage(receiverExpr.suggestionsForBadMemberName(memberName)) 219 errorMsg = 'Cannot find a definition for "[memberName]" in "[receiverExpr.toCobraSource]"[receiverExpr.whoseTypeIsMessage].[suggs]' 220 branch throwOrRecord 221 on 1, .throwError(errorMsg) 222 on 2, .recordError(errorMsg) 223 else, throw FallThroughException(throwOrRecord) 201 224 202 225 … … 506 529 type = .compiler.passThroughType 507 530 else 508 left = dotNode.left 509 suggs = left.suggestionsForBadMemberName(_name) 510 isBoxAccess = left inherits IdentifierExpr and (left to IdentifierExpr).definition inherits Box # like "Console.writeLine" where the receiver is a literal class or struct reference 511 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 512 .throwError('Cannot find a definition for "[_name]" in "[left.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 531 .throwCannotFindMemberError(dotNode.left, _name) 513 532 else 514 533 if not possibleDefinition.isCallable … … 956 975 def toCobraSource as String is override 957 976 return _name 977 978 def whoseTypeIsMessage as String 979 """ 980 Customized to return '' for boxes. 981 """ 982 # TODO: should cover other types like `int`. maybe that's a TypeExpr? 983 return if(.definition inherits Box, '', base.whoseTypeIsMessage) 958 984 959 985 … … 1282 1308 _type = .compiler.nilableDynamicType 1283 1309 return 1284 suggs = .binarySuperNode.left.suggestionsForBadMemberName(_name) 1285 isBoxAccess = left inherits IdentifierExpr and (left to IdentifierExpr).definition inherits Box # like "Console.writeLine" where the receiver is a literal class or struct reference 1286 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 1287 .throwError('Cannot find a definition for "[_name]" in "[left.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 1310 .throwCannotFindMemberError(left, _name) 1288 1311 assert _definition 1289 1312 if _definition inherits IType … … 1311 1334 1312 1335 if _definition inherits BoxMember 1313 _bindImpBoxMember(_definition, isBoxAccess, left)# resolve overloads1336 _bindImpBoxMember(_definition, left) # resolve overloads 1314 1337 else 1315 1338 # TODO: type access like enum, class, delegate … … 1317 1340 assert _type 1318 1341 1319 def _bindImpBoxMember(defn as BoxMember, isBoxAccess as bool,left as Expr)1342 def _bindImpBoxMember(defn as BoxMember, left as Expr) 1320 1343 # resolve overloads 1321 1344 if defn inherits MemberOverload … … 1340 1363 else if defn.isProtected 1341 1364 if not .compiler.curBox.isDescendantOf(defn.parentBox) 1342 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 1343 .throwError('Cannot access protected "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') 1365 .throwError('Cannot access protected "[_name]" in "[left.toCobraSource]"[left.whoseTypeIsMessage].') 1344 1366 else if defn.isPrivate 1345 1367 if not .compiler.curBox is defn.parentBox 1346 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 1347 .throwError('Cannot access private "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') 1368 .throwError('Cannot access private "[_name]" in "[left.toCobraSource]"[left.whoseTypeIsMessage].') 1348 1369 else if defn.isInternal 1349 1370 # TODO … … 1509 1530 if not arg.left inherits IdentifierExpr 1510 1531 .recordError('General purpose assignments are not allowed as arguments. Assignment syntax can only be used for keyword arguments.') 1511 if not expr.receiverType.isDynamicOrPassThrough1532 else if not expr.receiverType.isDynamicOrPassThrough 1512 1533 propertyName = (arg.left to IdentifierExpr).name 1513 1534 if expr.memberForName(propertyName) is nil 1514 suggs = .expr.suggestionsForBadMemberName(propertyName) 1515 isBoxAccess = expr inherits IdentifierExpr and (expr to IdentifierExpr).definition inherits Box # like "Console.writeLine" where the receiver is a literal class or struct reference 1516 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[expr.receiverType.name]"') 1517 .recordError('Cannot find a definition for "[propertyName]" in "[expr.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 1535 .recordCannotFindMemberError(expr, propertyName) 1518 1536 arg.right.bindImp # 'x=y' has special treatment in arguments 1519 1537 else
