Ticket #189: tkt-189-augment-and-cleanup.patch
File tkt-189-augment-and-cleanup.patch, 11.2 KB (added by hopscc, 12 years ago) |
---|
-
Source/BackEndCommon/CurlyWriter.cobra
22 22 if _initialBufferSize is nil 23 23 s = Environment.getEnvironmentVariable('COBRA_INTERNAL_GENCODEINITIALBUFFERSIZE') 24 24 if s is nil or s.trim == '', _initialBufferSize = 128 * 1024 25 else, _initialBufferSize = int.parse(s )25 else, _initialBufferSize = int.parse(s to !) 26 26 _sb = StringBuilder(_initialBufferSize to !) 27 27 _cobraLineNum = _curlyLineNum = 1 28 28 _curlyToCobraLineNum = {1 : 1} -
Source/Expr.cobra
281 281 """ 282 282 return ' whose type is "[.receiverType.name]"' 283 283 284 def _paramsCountMsg(defnName as String, params as IList<of Param>, args as IList<of Expr>) as String 285 item = if(defnName == r'[]', 'indexer', 'method') 286 countStr = if(args.count == 0, 'no arguments', '[args.count]') 287 countStr += if(args.count == 1, ' is', ' are') 288 detail = _paramsVsArgsString(defnName, params, args) 289 priMsg =('The [item] "[defnName]" is expecting [params.count] argument[Utils.plural(params)], but [countStr] being supplied in this call. [detail]') 290 return priMsg 291 292 def _paramsVsArgsString(defnName as String, params as IList<of Param>, args as IList<of Expr>) as String 293 """ 294 Generate a string augmenting error messages for calls with mismatched parameters and args. 295 List the declared arglist signature and calling Types. 296 """ 297 item='' 298 if defnName == r'[]' 299 defnName = '' 300 item = 'indexer arglist ' 301 sb = StringBuilder('The [item]declaration is "[defnName](') 302 sep='' 303 for param in params 304 sb.append(sep) 305 sep=', ' 306 sb.append('[param.name] as [param.type.name]') 307 sb.append(')"') 308 # TODO append definition return Type (if any)? 309 if args.count 310 sb.append(', the call is supplying an arglist of type[Utils.plural(args)] "(') 311 sep='' 312 for arg in args 313 sb.append(sep) 314 sep=', ' 315 sb.append('[arg.type.name]') 316 sb.append(')".') 317 return sb.toString 318 284 319 def throwCannotFindMemberError(receiverExpr as Expr, memberName as String) 285 320 __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 1) 286 321 … … 716 751 winner = definition.computeBestOverload(.args, .genericArgTypes, true) 717 752 sharp'definition = winner' 718 753 type = winner.resultType 719 /# 720 to-do: 2012-07-01 CE: the following just isn't ready754 /# #/ 755 #to-do: 2012-07-01 CE: the following just isn't ready 721 756 if winner inherits BoxMember # .no-warnings. 722 757 if winner.name not in ['format', 'invoke', 'split', 'sort'] # to-do: hack 723 758 params = winner.params … … 875 910 if _name=='toString' # to-do: hack: because many structs like Decimal have a toString() overload which cannot currently be expressed in SystemInterfaces.cobra 876 911 return false 877 912 else 878 .throwError( 'The method "[definition.name]" is expecting [params.count] argument[Utils.plural(params)], but [args.count] are being supplied in this call.')913 .throwError(_paramsCountMsg(definition.name, params, args)) #'The method "[definition.name]" is expecting [params.count] argument[Utils.plural(params)], but [countStr] being supplied in this call.' 879 914 return true 880 915 881 916 def _inferOutArgs(args as IList<of Expr>, params as IList<of Param>, warn as bool) 882 917 for num, arg in args.numbered 883 918 if _undefinedOutArg(arg) … … 925 960 print '<> param.type =', param.type 926 961 print '<> param.ifInheritsStack.count =', param.ifInheritsStack.count 927 962 if arg.type inherits NilableType and not param.type inherits NilableType and arg.type.nonNil.isAssignableTo(param.type) 928 arg.recordError('Argument [i+1] of method "[_name]" expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]).') 963 detail = _paramsVsArgsString(_name, params, args) 964 arg.recordError('Argument [i+1] of method "[_name]" expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]). [detail]') 929 965 else 930 arg.recordError('Argument [i+1] of method "[_name]" expects type [param.type.name], but the call is supplying type [arg.type.name].') 966 detail = _paramsVsArgsString(_name, params, args) 967 arg.recordError('Argument [i+1] of method "[_name]" expects type [param.type.name], but the call is supplying type [arg.type.name]. [detail]') 931 968 932 969 def _toErrorPhrase(d as Direction) as String 933 970 branch d … … 1502 1539 return 1503 1540 1504 1541 if not hasVari and args.count <> params.count 1505 .throwError( 'The indexer is expecting [params.count] argument[Utils.plural(params)], but [args.count] are being supplied in this call.')1542 .throwError(_paramsCountMsg(r'[]', params, args)) # 'The indexer is expecting [params.count] argument[Utils.plural(params)], but [countStr] being supplied in this call.[msg]' 1506 1543 for i in 0 : args.count 1507 1544 arg = args[i] 1508 1545 param = params[i] … … 1518 1555 print '<> param = ' stop 1519 1556 param.writeDeepString 1520 1557 if arg.type inherits NilableType and not param.type inherits NilableType and arg.type.nonNil.isAssignableTo(param.type) 1521 .throwError('Argument [i+1] of indexer expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]).') 1558 detail = _paramsVsArgsString(r'[]', params, args) 1559 .throwError('Argument [i+1] of indexer expects a non-nilable type ([param.type.name]), but the call is supplying a nilable type ([arg.type.name]). [detail]') 1522 1560 else 1523 .throwError('Argument [i+1] of indexer expects type [param.type.name], but the call is supplying type [arg.type.name].') 1561 detail = _paramsVsArgsString(r'[]', params, args) 1562 .throwError('Argument [i+1] of indexer expects type [param.type.name], but the call is supplying type [arg.type.name]. [detail]') 1524 1563 1525 1564 def toCobraSource as String is override 1526 1565 sb = StringBuilder() … … 1718 1757 else if defn inherits AbstractMethod 1719 1758 params = defn.params 1720 1759 if params.count <> 0 and not (params.count == 1 and params[0].type inherits VariType) 1721 .throwError( 'The method "[defn.name]" is expecting [params.count] argument[Utils.plural(params)], but no arguments are being supplied in this call.')1760 .throwError(_paramsCountMsg(defn.name, params, List<of Expr>())) # 'The method "[defn.name]" is expecting [params.count] argument[Utils.plural(params)], but no arguments are being supplied in this call.' 1722 1761 else if .name <> 'getType' # ug, more special handling for getType 1723 1762 box = .binarySuperNode.left.type to? Box 1724 1763 if box -
Source/Boxes.cobra
99 99 100 100 def _allBaseTypes(memo as Set<of Box>) as Box* 101 101 if .baseClass 102 if .baseClass not in memo 102 bc = .baseClass to ! 103 if bc not in memo 103 104 memo.add(.baseClass to !) 104 105 yield .baseClass to ! 105 106 for bt in .baseClass.allBaseTypes -
Source/SubversionUtils.cobra
50 50 re = Regex(r"/!svn/ver/(?'version'[0-9]*)/") 51 51 for match as Match in re.matches(fileText) 52 52 revInt, revText = 0, match.groups['version'].value 53 if int.tryParse(revText , out revInt) and revInt > maxVer, maxVer = revInt53 if int.tryParse(revText to !, out revInt) and revInt > maxVer, maxVer = revInt 54 54 if maxVer > int.minValue, return maxVer 55 55 return nil 56 56 -
Source/BackEndClr/ScanClrType.cobra
182 182 return Assembly.loadFrom(assemblyFileName) 183 183 184 184 def _onReflectionOnlyAssemblyResolve(sender, args as ResolveEventArgs) as Assembly? 185 assName = args.name 185 assName = args.name to ! 186 186 rv = .referenceVerbosity - 1 187 187 if rv < 0, rv = 0 188 188 if assName in _didLoadAssemblies -
Tests/820-errors/200-expressions/415-calls-wrong-indexer-detail.cobra
1 # wrong count and type calls on an indexer - chk detail info 2 class X 3 4 def main is shared 5 a = X() 6 7 x = a['ss'] # .error. indexer arglist declaration 8 9 x = a[1, 2] # .error. arglist of types "(int, int)" 10 CobraCore.noOp(x) 11 12 13 get [i as int] as int 14 return 1 -
Tests/820-errors/200-expressions/410-calls-wrong-method.cobra
1 # Calls with wrong counts and types 2 class X 3 4 def main is shared 5 a = X() 6 a.catCall(1, 'ss') # OK 7 a.catCall('ss') # .error. expecting 2 arguments 8 a.catCall('ss', 1, 33.3, X()) # .error. expecting 2 arguments 9 a.mooseCall #.error. no arguments are being supplied 10 11 a.duckCall(1) #.error. expects type String 12 a.duckCall(1, 'moooo') # .error. 2 are being supplied 13 14 n as String? = 'xx' 15 a.duckCall(n) #.error. expects a non-nilable type (String) 16 a.noCall(1.1) #.error. expects type String? 17 18 19 def catCall(a as int, s as String) 20 pass 21 22 def duckCall(s as String) 23 pass 24 25 def mooseCall(s as String) 26 pass 27 28 def noCall(s as String?) 29 pass 30 31 get [i as int] as int 32 return 1 -
Tests/820-errors/200-expressions/412-calls-wrong-method-detail.cobra
1 # Calls with wrong counts/types - chk detail info 2 class X 3 4 def main is shared 5 a = X() 6 a.catCall(1, 'ss') # OK 7 a.catCall('ss') # .error. supplying an arglist of type "(String)" 8 a.catCall('ss', 1, 33.3, X()) # .error. supplying an arglist of types 9 a.mooseCall #.error. mooseCall(s as String) 10 11 a.duckCall(1) #.error. supplying an arglist of type "(int)" 12 a.duckCall(1, 'moooo') # .error. arglist of types "(int, String)" 13 14 n as String? = 'xx' 15 a.duckCall(n) #.error. arglist of type "(String?)" 16 a.noCall(1.1) #.error. declaration is "noCall(s as String?)" 17 18 19 def catCall(a as int, s as String) 20 pass 21 22 def duckCall(s as String) 23 pass 24 25 def mooseCall(s as String) 26 pass 27 28 def noCall(s as String?) 29 pass 30 31 get [i as int] as int 32 return 1