Wiki

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

     
    2222        if _initialBufferSize is nil 
    2323            s = Environment.getEnvironmentVariable('COBRA_INTERNAL_GENCODEINITIALBUFFERSIZE') 
    2424            if s is nil or s.trim == '', _initialBufferSize = 128 * 1024 
    25             else, _initialBufferSize = int.parse(s) 
     25            else, _initialBufferSize = int.parse(s to !) 
    2626        _sb = StringBuilder(_initialBufferSize to !) 
    2727        _cobraLineNum = _curlyLineNum = 1 
    2828        _curlyToCobraLineNum = {1 : 1} 
  • Source/Expr.cobra

     
    281281        """ 
    282282        return ' whose type is "[.receiverType.name]"' 
    283283     
     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         
    284319    def throwCannotFindMemberError(receiverExpr as Expr, memberName as String) 
    285320        __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 1) 
    286321 
     
    716751                            winner = definition.computeBestOverload(.args, .genericArgTypes, true) 
    717752                            sharp'definition = winner' 
    718753                            type = winner.resultType 
    719                             /# 
    720                             to-do: 2012-07-01 CE: the following just isn't ready 
     754                            /# #/ 
     755                            #to-do: 2012-07-01 CE: the following just isn't ready 
    721756                            if winner inherits BoxMember # .no-warnings. 
    722757                                if winner.name not in ['format', 'invoke', 'split', 'sort']  # to-do: hack 
    723758                                    params = winner.params 
     
    875910            if _name=='toString'  # to-do: hack: because many structs like Decimal have a toString() overload which cannot currently be expressed in SystemInterfaces.cobra 
    876911                return false 
    877912            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.' 
    879914        return true 
    880  
     915         
    881916    def _inferOutArgs(args as IList<of Expr>, params as IList<of Param>, warn as bool)  
    882917        for num, arg in args.numbered 
    883918            if _undefinedOutArg(arg) 
     
    925960                    print '<> param.type =', param.type 
    926961                    print '<> param.ifInheritsStack.count =', param.ifInheritsStack.count 
    927962                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]') 
    929965                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]') 
    931968 
    932969    def _toErrorPhrase(d as Direction) as String 
    933970        branch d 
     
    15021539            return 
    15031540             
    15041541        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]' 
    15061543        for i in 0 : args.count 
    15071544            arg = args[i] 
    15081545            param = params[i] 
     
    15181555                    print '<> param = ' stop 
    15191556                    param.writeDeepString 
    15201557                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]') 
    15221560                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]') 
    15241563                         
    15251564    def toCobraSource as String is override 
    15261565        sb = StringBuilder() 
     
    17181757            else if defn inherits AbstractMethod 
    17191758                params = defn.params 
    17201759                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.' 
    17221761                else if .name <> 'getType'  # ug, more special handling for getType 
    17231762                    box = .binarySuperNode.left.type to? Box 
    17241763                    if box 
  • Source/Boxes.cobra

     
    9999 
    100100    def _allBaseTypes(memo as Set<of Box>) as Box* 
    101101        if .baseClass 
    102             if .baseClass not in memo 
     102            bc = .baseClass to ! 
     103            if bc not in memo 
    103104                memo.add(.baseClass to !) 
    104105                yield .baseClass to ! 
    105106            for bt in .baseClass.allBaseTypes 
  • Source/SubversionUtils.cobra

     
    5050                re = Regex(r"/!svn/ver/(?'version'[0-9]*)/") 
    5151                for match as Match in re.matches(fileText) 
    5252                    revInt, revText = 0, match.groups['version'].value 
    53                     if int.tryParse(revText, out revInt) and revInt > maxVer, maxVer = revInt 
     53                    if int.tryParse(revText to !, out revInt) and revInt > maxVer, maxVer = revInt 
    5454                if maxVer > int.minValue, return maxVer 
    5555            return nil 
    5656 
  • Source/BackEndClr/ScanClrType.cobra

     
    182182                return Assembly.loadFrom(assemblyFileName) 
    183183 
    184184    def _onReflectionOnlyAssemblyResolve(sender, args as ResolveEventArgs) as Assembly? 
    185         assName = args.name 
     185        assName = args.name to ! 
    186186        rv = .referenceVerbosity - 1 
    187187        if rv < 0, rv = 0 
    188188        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 
     2class 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 
     2class 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 
     2class 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