fix(conf): reject pointer-to-map environment with a clear error - #987
fix(conf): reject pointer-to-map environment with a clear error#987jaideeppyne wants to merge 3 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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.
Per expr-lang#825 (wontfix for deref-support): rather than dereferencing a *map env, reject it with a descriptive message instead of the opaque "reflect: call of reflect.Value.Len on ptr to non-array Value" panic. Passing a map by value is unaffected.
Detect pointer-to-map by type so a nil *map is rejected with the same message as a non-nil one, instead of the generic "unknown type" panic. Pointer-to-struct envs are unaffected.
|
Reconciled with #825's direction: this now rejects On the nil-pointer case you flagged: I detect the pointer-to-map by type now, so a nil |
Fixes #825
Passing a pointer to a map as the environment panicked at compile time:
EnvWithCacheselects 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*mapenv 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 onmasterand passes with this change.gofmt,go vet, and the full suite are green.