Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get function does not return nil when map value type is not inferface{} #723

Open
mambla opened this issue Oct 28, 2024 · 1 comment
Open
Labels

Comments

@mambla
Copy link

mambla commented Oct 28, 2024

When map is of type map[string]string (for example its source is the env) the get function returns an empty string instead of nil when the key doesn't exist

package main

import (
	"fmt"

	"github.com/expr-lang/expr"
)

func main() {
	emptyMap := make(map[string]string)
	env := map[string]interface{}{
		"empty_map": emptyMap,
	}

	code := `get(empty_map, "non_existing_key")`

	program, err := expr.Compile(code, expr.Env(env))
	if err != nil {
		panic(err)
	}

	output, err := expr.Run(program, env)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%T, %s", output, output)
}

@antonmedv antonmedv added the bug label Oct 28, 2024
@antonmedv
Copy link
Member

Yes. Looks like a default value is returned instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants