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

Typed int with ref equality #730

Open
antonmedv opened this issue Nov 20, 2024 · 4 comments
Open

Typed int with ref equality #730

antonmedv opened this issue Nov 20, 2024 · 4 comments
Labels

Comments

@antonmedv
Copy link
Member

          Can I get the pointer value of the struct Env?

Playground:https://go.dev/play/p/WIj3_3NoR2z

package main

import (
	"fmt"

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

type ModeEnum int

const (
	ModeEnumA ModeEnum = 1
	ModeEnumB ModeEnum = 2
)

type Env struct {
	Mode *ModeEnum
}

func main() {
	code := `Mode == 1`

	tmp := ModeEnumA

	env := map[string]any{
		"Mode": &tmp,
	}

	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.Println(output)
}

It prints false, but the expectation is true

Originally posted by @Cassius0924 in #154 (comment)

@antonmedv antonmedv added the bug label Nov 20, 2024
@Cassius0924
Copy link

If it is repaired, should the Mode be wrapped with an int function? like:

	code := `int(Mode) == 1`

Or will Mode be converted implicitly?

	code := `Mode == 1`

@Cassius0924
Copy link

Is it possible to add a parameter to control whether implicit conversion is performed?

@antonmedv
Copy link
Member Author

The problem is with typed int field. Expr see it as an int and assumes no deref is needed. I think we can try to make type checker more advance.

@Cassius0924
Copy link

Are you already fixing it?

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