Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when attempting to initialize a field which references an interface #47

Open
kevin-lindsay-1 opened this issue Nov 1, 2023 · 1 comment

Comments

@kevin-lindsay-1
Copy link

kevin-lindsay-1 commented Nov 1, 2023

type Thingy struct {
  Context context.Context
}
func (obj *Thingy) SetDefaults() {
  if defaults.CanUpdate(obj.Context) { // panic
    obj.Context = context.Background()
  }
}
panic: reflect: call of reflect.Value.Type on zero Value

reflect.Value.typeSlow
	/usr/local/go/src/reflect/value.go:2634
reflect.Value.Type
	/usr/local/go/src/reflect/value.go:2629
github.com/creasty/defaults.isInitialValue
	/usr/root/function/vendor/github.com/creasty/defaults/defaults.go:221
github.com/creasty/defaults.CanUpdate
	/usr/root/function/vendor/github.com/creasty/defaults/defaults.go:243
function/internal/common/utils.(*InvokeOpts).SetDefaults
	/usr/root/function/internal/common/utils/invoke.go:33
github.com/creasty/defaults.callSetter
	/usr/root/function/vendor/github.com/creasty/defaults/setter.go:10
github.com/creasty/defaults.Set
	/usr/root/function/vendor/github.com/creasty/defaults/defaults.go:42
// creasty/defaults/defaults.go#220
func isInitialValue(field reflect.Value) bool {
  return reflect.DeepEqual(reflect.Zero(field.Type()).Interface(), field.Interface())
}
@kevin-lindsay-1
Copy link
Author

hi btw, i like ur lib ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant