From f56408714c1f010b977def5d05e402f957eab46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Soul=C3=A9?= Date: Mon, 18 Mar 2024 13:12:59 +0100 Subject: [PATCH] fix: smuggle hooks can return interface, as the doc always said MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime Soulé --- internal/hooks/hooks.go | 3 +-- internal/hooks/hooks_test.go | 10 ---------- td/t_hooks_test.go | 8 ++++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/internal/hooks/hooks.go b/internal/hooks/hooks.go index 1bd5761a..21ca1fbc 100644 --- a/internal/hooks/hooks.go +++ b/internal/hooks/hooks.go @@ -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 diff --git a/internal/hooks/hooks_test.go b/internal/hooks/hooks_test.go index 05c6daea..86e829ea 100644 --- a/internal/hooks/hooks_test.go +++ b/internal/hooks/hooks_test.go @@ -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() diff --git a/td/t_hooks_test.go b/td/t_hooks_test.go index 1e5cd64f..c2e53008 100644 --- a/td/t_hooks_test.go +++ b/td/t_hooks_test.go @@ -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())