Skip to content

fix(conf): deref pointer-to-map environment instead of panicking - #987

Open
jaideeppyne wants to merge 1 commit into
expr-lang:masterfrom
jaideeppyne:fix/ptr-to-map-env-panic
Open

fix(conf): deref pointer-to-map environment instead of panicking#987
jaideeppyne wants to merge 1 commit into
expr-lang:masterfrom
jaideeppyne:fix/ptr-to-map-env-panic

Conversation

@jaideeppyne

Copy link
Copy Markdown

Fixes #825

Passing a pointer to a map as the environment panicked at compile time:

panic: reflect: call of reflect.Value.Len on ptr to non-array Value

EnvWithCache selects the map branch using the dereferenced value's kind, but then read the length and keys from the original pointer value. This iterates the dereferenced value in the map branch, so a *map env is treated exactly like the map it points to — same strict mode and element types — matching the existing behaviour for pointer-to-struct environments.

Added a regression test under test/issues/825/ covering compile+run, strict unknown-name rejection, and element-type inference through the pointer. It panics on master and passes with this change. gofmt, go vet, and the full suite are green.

EnvWithCache selected the map branch using the dereferenced value's
kind, but then read the map length and keys from the original (pointer)
value. Passing a *map as the env therefore panicked with:

    reflect: call of reflect.Value.Len on ptr to non-array Value

Iterate the dereferenced value in the map branch so a pointer-to-map env
is treated exactly like the map it points to (same strict mode and
element types), matching the existing behaviour for pointer-to-struct
environments.

Fixes expr-lang#825

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: jaideeppyne <jaideeppyne1997@gmail.com>

@sanmaxdev sanmaxdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation and focused regression tests pass. Before this lands, please reconcile the behavior with #825: the issue is labeled wontfix, and the maintainer's direction was to reject *map input with an error. This patch instead supports non-nil pointers while nil pointers still panic as an unknown type. A decision on support versus rejection seems needed, along with a nil-pointer test for the chosen contract.

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

Successfully merging this pull request may close these issues.

Panic when using pointer-type map as environment

2 participants