Ticket #323: overload-and-dyn-arg.patch
File overload-and-dyn-arg.patch, 3.8 KB (added by hopscc, 12 years ago) |
---|
-
Source/Expr.cobra
750 750 sharp'definition = winner' 751 751 type = winner.resultType 752 752 if winner inherits BoxMember # .no-warnings. 753 # to-do: 2012-07-01 CE: the following just isn't ready754 if winner.name not in ['format', 'invoke', 'split', 'sort'] # to-do: hack 753 # to-do: 2012-07-01 CE: the following isn't fully ready due defn.computeBestOverload deficiencies 754 if winner.name not in ['format', 'invoke', 'split', 'sort'] # to-do: hack 755 755 params = winner.params 756 756 if _checkParamsCount(winner, args, params) 757 757 if needInferOutArgs, _inferOutArgs(args, params, false) 758 _checkArgsAssignable(winner, args, params)758 _checkArgsAssignable(winner, true, args, params) 759 759 else 760 760 type = definition.resultType 761 761 if _didVariArgs(definition) 762 762 params = definition.params 763 _checkArgsAssignable(definition, args, params)763 _checkArgsAssignable(definition, false, args, params) 764 764 else 765 765 definition = _checkGenerics(definition, inout type) 766 766 if not definition.hasParams … … 769 769 params = definition.params 770 770 if _checkParamsCount(definition, args, params) 771 771 if needInferOutArgs, _inferOutArgs(args, params, false) 772 _checkArgsAssignable(definition, args, params)772 _checkArgsAssignable(definition, false, args, params) 773 773 774 774 _checkInOutArguments 775 775 _checkVisibility(definition, dotNode.left) … … 927 927 sugg = 'You may want to disambiguate this by declaring the variable explicitly.' 928 928 .compiler.warning(this, 'Cobra has implicitly declared a variable "[newDefn.name] as [newDefn.type.name]" for an undefined out parameter variable but the type inferred may not be correct as the method called is overloaded. [sugg]') 929 929 930 def _checkArgsAssignable(definition as BoxMember, args as IList<of Expr>, params as IList<of Param>)930 def _checkArgsAssignable(definition as BoxMember, defnIsOverload as bool, args as IList<of Expr>, params as IList<of Param>) 931 931 for i in args.count 932 932 arg = args[i] 933 933 param = params[i] … … 944 944 if param.direction <> arg.direction 945 945 arg.recordError('Argument [i+1] of method "[_name]" expects [_toErrorPhrase(param.direction)] parameter, but the call is supplying [_toErrorPhrase(arg.direction)] one.') 946 946 if arg.canBeAssignedTo(param.type) 947 arg.contextType = param.type 947 # condition below is workaround for ticket:323 948 # - wrong choice of overload definition and (bad) cast of dynamic arg to wrong type 949 # TODO: chk/remove condition check when ticket:130 addressed 950 if defnIsOverload and arg.type.nonNil inherits DynamicType 951 pass 952 else 953 arg.contextType = param.type 948 954 else if param.type inherits GenericParam 949 955 # ..\Tests\240-generics\400-generic-methods\100-generic-method.cobra 950 956 # HACK for generic method args which need proper type checking like anything else -
Tests/820-errors/200-expressions/416-dynamic-arg-cast.cobra
1 #ticket:323 Invalid cast Exception from wrong cast (char fm first overload) of dynamic arg 2 # TODO: recheck when ticket:130 is addressed 3 class DynArgOverload 4 5 def foo(c as char) 6 pass 7 8 def foo(s as String) 9 pass 10 11 def foo(obj as Object) 12 pass 13 14 def main 15 x = 'aoeu' to dynamic 16 .foo(x)