From 4fd90b5d52c7b2479382130b7cd3fc02a47bbd2d Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 22 Aug 2023 18:07:35 -0400 Subject: [PATCH] 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! --- lang/types/value.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lang/types/value.go b/lang/types/value.go index 89adaa39..823ef0dd 100644 --- a/lang/types/value.go +++ b/lang/types/value.go @@ -263,6 +263,9 @@ func Into(v Value, rv reflect.Value) error { } 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 // mustInto ensures rv is in a list of compatible types before attempting to reflect it