Skip to content

Commit

Permalink
fix: smuggle hooks can return interface, as the doc always said
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
  • Loading branch information
maxatome committed Mar 18, 2024
1 parent 679b2d7 commit 8f37392
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions internal/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ func (i *Info) AddSmuggleHooks(fns []any) error {
if !ft.IsVariadic() &&
ft.NumIn() == 1 &&
ft.In(0).Kind() != reflect.Interface &&
(ft.NumOut() == 1 || (ft.NumOut() == 2 && ft.Out(1) == types.Error)) &&
ft.Out(0).Kind() != reflect.Interface {
(ft.NumOut() == 1 || (ft.NumOut() == 2 && ft.Out(1) == types.Error)) {
i.Lock()
prop := i.props[ft.In(0)]
prop.smuggle = vfn
Expand Down
10 changes: 0 additions & 10 deletions internal/hooks/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,6 @@ func TestAddSmuggleHooks(t *testing.T) {
smuggle: func(a int) (int, int) { return 0, 0 },
err: "expects: func (A) (B[, error]) not func(int) (int, int) (@1)",
},
{
name: "return interface",
smuggle: func(a int) any { return 0 },
err: "expects: func (A) (B[, error]) not func(int) interface {} (@1)",
},
{
name: "return interface, error",
smuggle: func(a int) (any, error) { return 0, nil },
err: "expects: func (A) (B[, error]) not func(int) (interface {}, error) (@1)",
},
} {
i := hooks.NewInfo()

Expand Down
8 changes: 8 additions & 0 deletions td/t_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func TestWithSmuggleHooks(tt *testing.T) {
got: "1234",
expected: 1234,
},
{
name: "reflect2any",
cmp: func(v reflect.Value) any {
return v.Interface()
},
got: reflect.ValueOf(123),
expected: 123,
},
} {
tt.Run(tst.name, func(tt *testing.T) {
ttt := test.NewTestingTB(tt.Name())
Expand Down

0 comments on commit 8f37392

Please sign in to comment.