compiler: disallow generic method receiver
Either non-pointer or pointer, both cases are disallowed to be generic. Need to be reverted and properly handled within the scope of #2376. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
415d44792a
commit
1b1b454ce4
2 changed files with 73 additions and 0 deletions
38
pkg/compiler/generics_test.go
Normal file
38
pkg/compiler/generics_test.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package compiler_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGenericMethodReceiver(t *testing.T) {
|
||||
t.Run("star expression", func(t *testing.T) {
|
||||
src := `
|
||||
package receiver
|
||||
type Pointer[T any] struct {
|
||||
value T
|
||||
}
|
||||
func (x *Pointer[T]) Load() *T {
|
||||
return &x.value
|
||||
}
|
||||
`
|
||||
_, _, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||
require.ErrorIs(t, err, compiler.ErrGenericsUnsuppored)
|
||||
})
|
||||
t.Run("ident expression", func(t *testing.T) {
|
||||
src := `
|
||||
package receiver
|
||||
type Pointer[T any] struct {
|
||||
value T
|
||||
}
|
||||
func (x Pointer[T]) Load() *T {
|
||||
return &x.value
|
||||
}
|
||||
`
|
||||
_, _, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil)
|
||||
require.ErrorIs(t, err, compiler.ErrGenericsUnsuppored)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue