Ticket #271: generic-method-callchks.patch
File generic-method-callchks.patch, 2.4 KB (added by hopscc, 14 years ago) |
---|
-
Source/Expr.cobra
784 784 def _checkGenerics(definition as BoxMember, type as inout IType?) as BoxMember 785 785 if .genericArgTypes and .genericArgTypes.count 786 786 if definition inherits Method 787 definition = definition.constructedMethodWith(.genericArgTypes to !) 788 type = definition.resultType 787 if not definition.isGenericDef 788 .recordError('Method "[definition.name]" is being invoked as a generic but it is not declared as a generic method.') 789 else if .genericArgTypes.count <> definition.genericParams.count 790 .recordError('Generic method "[definition.name]" has a mismatch on the number of generic arg types. It is being called with [.genericArgTypes.count] but is declared with [definition.genericParams.count].') 791 else 792 definition = definition.constructedMethodWith(.genericArgTypes to !) 793 type = definition.resultType 789 794 else 790 795 .throwError('Cannot pass type arguments to "[definition.name]" because it is a [definition.getType.name].') # @@ _definition.englishName; also might need this error in other locations 791 796 return definition -
Tests/240-generics/400-generic-methods/212-types-count-err.cobra
1 class GenErr 2 # 2 arg types generic 3 def calc<of T, T1>(param as T) as T1 is shared 4 return param 5 6 def main is shared 7 # calling with one arg type 8 res = .calc<of int>(1) # .error. 9 CobraCore.noOp(res) -
Tests/240-generics/400-generic-methods/210-call-to-nongeneric-err.cobra
1 class GenErr 2 # this is not a generic method 3 def calc(param as int) as int 4 return param % 2 5 6 def main 7 # this is calling it like it is 8 res = .calc<of int>(1) # .error. invoked as a generic but it is not declared as a generic 9 CobraCore.noOp(res)