diff --git a/proptools/configurable.go b/proptools/configurable.go index 4dfe007..55e4fb7 100644 --- a/proptools/configurable.go +++ b/proptools/configurable.go @@ -502,8 +502,12 @@ func (c *Configurable[T]) AddPostProcessor(p func(T) T) { // See Configurable.evaluate for more details on the postProcessors algorithm // and data structure. num_links := c.inner.numLinks() - if c.postProcessors == nil || len(*c.postProcessors) == 0 { - c.postProcessors = &[][]postProcessor[T]{{{ + if c.postProcessors == nil { + var nilCases []ConfigurableCase[T] + c.initialize(nil, "", nil, nilCases) + } + if len(*c.postProcessors) == 0 { + *c.postProcessors = [][]postProcessor[T]{{{ f: p, start: 0, end: num_links, diff --git a/proptools/configurable_test.go b/proptools/configurable_test.go index f3ea417..f608a45 100644 --- a/proptools/configurable_test.go +++ b/proptools/configurable_test.go @@ -43,6 +43,24 @@ func TestPostProcessor(t *testing.T) { } } +func TestPostProcessorWhenPassedToHelperFunction(t *testing.T) { + prop := NewConfigurable[[]string](nil, nil) + prop.AppendSimpleValue([]string{"a"}) + prop.AppendSimpleValue([]string{"b"}) + + helper := func(p Configurable[[]string]) { + p.AddPostProcessor(addToElements("1")) + } + + helper(prop) + + expected := []string{"a1", "b1"} + x := prop.Get(&configurableEvalutorForTesting{}) + if !reflect.DeepEqual(x.Get(), expected) { + t.Fatalf("Expected %v, got %v", expected, x.Get()) + } +} + func addToElements(s string) func([]string) []string { return func(arr []string) []string { for i := range arr {