Skip to content

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

Closed
@mambla

Description

@mambla

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions