Skip to content

Conversation

@thevilledev
Copy link
Contributor

Previously, passing a pointer to a map (e.g. *map[string]any) to expr.Env() would cause a panic because reflection methods were called on the pointer value instead of the underlying map. With this change the value is first deref'd in the config before any map operations are performed.

Consequently, the vm.Run() method needs to dereference the env map. This ensures compatibility with the optimisations like OpLoadFast where the compiler determines the environment simply as map[string]any.

Regression test added.

Fixes #825.

Previously, passing a pointer to a map (e.g. `*map[string]any`)
to `expr.Env()` would cause a panic because reflection methods
were called on the pointer value instead of the underlying map.
With this change the value is first deref'd in the config before
any map operations are performed.

Consequently, the `vm.Run()` method needs to dereference the env
map. This ensures compatibility with the optimisations like
`OpLoadFast` where the compiler determines the environment simply
as `map[string]any`.

Regression test added.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
@antonmedv
Copy link
Member

But why would *map[string]any pointer to map is needed?


func (vm *VM) Run(program *Program, env any) (_ any, err error) {
if m, ok := env.(*map[string]any); ok && m != nil {
env = *m
Copy link
Member

Choose a reason for hiding this comment

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

I think Expr sloud allow to types as incoming env: struct, *struct and map[string]...

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