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

unexpected logical expression result #8

Closed
vjeantet opened this issue Mar 27, 2016 · 2 comments
Closed

unexpected logical expression result #8

vjeantet opened this issue Mar 27, 2016 · 2 comments
Assignees
Labels

Comments

@vjeantet
Copy link

Hello
|| and && operators does not seems to work as expected

    expression, _ := govaluate.NewEvaluableExpression("foo == true || bar == true")
    parameters := make(map[string]interface{}, 8)
    parameters["foo"] = true
    parameters["bar"] = false
    result, _ := expression.Evaluate(parameters)
    log.Printf("actual %t, expected : true \n", result)

    expression, _ = govaluate.NewEvaluableExpression("foo > 10  && bar > 10")
    parameters = make(map[string]interface{}, 8)
    parameters["foo"] = 1
    parameters["bar"] = 11
    result, _ = expression.Evaluate(parameters)
    log.Printf("actual %t, expected : false \n", result)

this code will evaluate false for the first result, and true for the second one.

Knetic added a commit that referenced this issue Mar 27, 2016
…on either side seem to result in opposite-intended results
@Knetic Knetic self-assigned this Mar 27, 2016
@Knetic Knetic added the bug label Mar 27, 2016
@Knetic
Copy link
Owner

Knetic commented Mar 27, 2016

Thanks for the report, especially the sample! There was a gap in my tests, and it made me think I could be clever and get by without doing a type assertion when evaluating logical operators. For whatever reason, nobody's hit this case until today.

Ought to be fixed as of dc6cef2, I added test cases for your examples and everything ought to work as expected. Let me know if you have any problems with the master branch.

@vjeantet
Copy link
Author

It works ! Thanks for being so quick to fix it !

Nice piece of code !

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