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

compare pointer and a string #490

Closed
gosom opened this issue Dec 4, 2023 · 1 comment
Closed

compare pointer and a string #490

gosom opened this issue Dec 4, 2023 · 1 comment
Labels

Comments

@gosom
Copy link

gosom commented Dec 4, 2023

Thanks for the great library.

I experience a "strange" behavior.

package main

import (
	"fmt"

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

type Env struct {
	A string
	B *string
}

func main() {
	code := `A == B`

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

	value := "ok"
	env := Env{
		A: value,
		B: &value,
	}

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

	fmt.Println(output)
}

Try in go playground .

I expect the output to be true but it is false.

Is this behavior intentional?
Reading another issue related to pointers I was with the impression that pointers
should be "hidden", since a lot of stakeholders are people who cannot code well.

changing the code to:

code := `A == (B ?? "")`

outputs true as expected.

Maybe this at least can be documented (if it's not already and I missed it) or
the comparison operator supports a comparison between strings and pointers to strings.

best

@antonmedv antonmedv added the bug label Dec 4, 2023
@antonmedv
Copy link
Member

It is a bug. If I flip expression to B == A - everything works.

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