diff --git a/aconfig_test.go b/aconfig_test.go index efb2cbf..2a91132 100644 --- a/aconfig_test.go +++ b/aconfig_test.go @@ -1061,7 +1061,7 @@ func TestDontFillFlagsIfDisabled(t *testing.T) { } } -func TestPassNonStructs(t *testing.T) { +func TestPassBadStructs(t *testing.T) { f := func(cfg interface{}) { t.Helper() @@ -1080,6 +1080,11 @@ func TestPassNonStructs(t *testing.T) { f([]string{}) f([4]string{}) f(func() {}) + + type S struct { + Foo int + } + f(S{}) } func TestBadRequiredTag(t *testing.T) { diff --git a/utils.go b/utils.go index 1e88eb1..c58fb41 100644 --- a/utils.go +++ b/utils.go @@ -15,6 +15,9 @@ func assertStruct(x interface{}) { panic("aconfig: nil should not be passed to the Loader") } value := reflect.ValueOf(x) + if value.Type().Kind() != reflect.Ptr { + panic("aconfig: destination must be a pointer") + } for value.Type().Kind() == reflect.Ptr { value = value.Elem() }