lang: types: Avoid a panic if it's not settable

We should check this for safety. An error is better than a panic. If we
try to set an unexported field, this would panic. We should prevent
being able to even type unify that though!
This commit is contained in:
James Shubin
2023-08-22 18:07:35 -04:00
parent 28c206da18
commit 4fd90b5d52

View File

@@ -263,6 +263,9 @@ func Into(v Value, rv reflect.Value) error {
} }
rv = rv.Elem() // un-nest rv from pointer rv = rv.Elem() // un-nest rv from pointer
} }
if !rv.CanSet() {
return fmt.Errorf("can't set value, is it unexported?")
}
// capture rv and v in a closure that is static for the scope of this Into() call // capture rv and v in a closure that is static for the scope of this Into() call
// mustInto ensures rv is in a list of compatible types before attempting to reflect it // mustInto ensures rv is in a list of compatible types before attempting to reflect it