diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index e4ac01a94..23ab6dede 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -563,6 +563,11 @@ func (c *codegen) checkGenericsFuncDecl(n *ast.FuncDecl, funcName string) error } } + // Generic function parameters type: func SumInts[V int64 | int32](vals []V) V + if n.Type.TypeParams != nil { + errGenerics = errors.New("function type parameters") + } + if errGenerics != nil { return fmt.Errorf("%w: %s has %s", ErrGenericsUnsuppored, funcName, errGenerics.Error()) } diff --git a/pkg/compiler/generics_test.go b/pkg/compiler/generics_test.go index 6a73d65c5..28eb00fda 100644 --- a/pkg/compiler/generics_test.go +++ b/pkg/compiler/generics_test.go @@ -36,3 +36,18 @@ func TestGenericMethodReceiver(t *testing.T) { require.ErrorIs(t, err, compiler.ErrGenericsUnsuppored) }) } + +func TestGenericFuncArgument(t *testing.T) { + src := ` + package sum + func SumInts[V int64 | int32 | int16](vals []V) V { // doesn't make sense with NeoVM, but still it's a valid go code. + var s V + for i := range vals { + s += vals[i] + } + return s + } +` + _, _, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil) + require.ErrorIs(t, err, compiler.ErrGenericsUnsuppored) +}