params: fix param value decoding

This commit is contained in:
Felix Lange 2025-07-24 12:51:20 +02:00
parent cf8af42646
commit 336a2dab56
2 changed files with 7 additions and 4 deletions

View file

@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"maps" "maps"
"math/big" "math/big"
"reflect"
"slices" "slices"
"strconv" "strconv"
"strings" "strings"
@ -171,7 +172,10 @@ func (cfg *Config2) UnmarshalJSON(input []byte) error {
return fmt.Errorf("expected JSON object for chain configuration") return fmt.Errorf("expected JSON object for chain configuration")
} }
// Now we're in the object. // Now we're in the object.
newcfg := Config2{activation: Activations{}} newcfg := Config2{
activation: make(Activations),
param: make(map[int]any),
}
for { for {
tok, err = dec.Token() tok, err = dec.Token()
if tok == json.Delim('}') { if tok == json.Delim('}') {
@ -227,7 +231,7 @@ func (cfg *Config2) decodeParameter(key string, dec *json.Decoder) error {
if err := dec.Decode(v); err != nil { if err := dec.Decode(v); err != nil {
return err return err
} }
cfg.param[id] = v cfg.param[id] = reflect.ValueOf(v).Elem().Interface()
return nil return nil
} }

View file

@ -101,8 +101,7 @@ func Define[V any](def T[V]) Parameter[V] {
optional: def.Optional, optional: def.Optional,
defaultValue: def.Default, defaultValue: def.Default,
new: func() any { new: func() any {
var z V return new(V)
return z
}, },
validate: func(v any, cfg *Config2) error { validate: func(v any, cfg *Config2) error {
if def.Validate == nil { if def.Validate == nil {