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

Equality is incorrect when nil is used as the left argument of == #1500

Merged
merged 14 commits into from
Mar 23, 2023

Conversation

elee1766
Copy link
Contributor

@elee1766 elee1766 commented Jan 1, 2023

hi!

this issue is sorta blocking for me so i thought i would try to fix it.

im still learning the codebase and understanding how yaegi works, but I thought I would attempt to add a test in the style of other tests as a start.

please let me know if there is anything i need to change / run, or if anyone knows perhaps a good place to start for tackling this issue

Fixes #1496

@CLAassistant
Copy link

CLAassistant commented Jan 1, 2023

CLA assistant check
All committers have signed the CLA.

@elee1766
Copy link
Contributor Author

elee1766 commented Jan 1, 2023

adding
fmt.Printf("equals: <%s> <%s> %v \n", t.id(), o.id(), t.id() == o.id())
to line type.go:1504 seems to show

equals:  <[]uint8> <nil> false
equals:  <bool> <bool> true
equals:  <nil> <[]uint8> false
equals:  <bool> <bool> true

which are the same, which perhaps means something is happening later down the line? will keep digging

oh, it seems that's just called by typecheck.go, and yeah those things are matching, so it must be down the line. sorry for the red herring!

@elee1766
Copy link
Contributor Author

elee1766 commented Jan 1, 2023

ok, so these two statements []byte{} == nil and nil == []byte{} seem to be getting optimized somewhere before interpretation?

i say this because the "equals" in "op.go" is not called for those operations (they are for a==false, b==false, and a==b though), but maybe i misunderstand

@elee1766
Copy link
Contributor Author

elee1766 commented Jan 1, 2023

ok, maybe third time is the charm

i added fmt.Printf(`nodes <%s> <%s> %v\n`, c0.name(), n.child[1].name(), value(f).IsNil())

to the frame function near run.go:3880. it seems that the difference materializes here.

so this is consistent with the behavior. It just checks if the first? value is nil, and if it is, returns true? hence why (nil==[]byte{}) returns true

but that means that uh, nil equality is completely broken broken then right?

ok

i updated the test just now, it seems that if nil is the first element in a comparison, the expression always evaluates to true.

@elee1766 elee1766 marked this pull request as ready for review January 1, 2023 04:06
@elee1766
Copy link
Contributor Author

elee1766 commented Jan 1, 2023

questions:

  1. i dont actually know if this check is 100% correct? i think it is more correct than the previous one. it matches go run now at least.

  2. i dont know if "nil" is valid in any binary operator that isnt aEqual. if its just aEqual, this fix should be fine?

  3. i couldn't run tests on my local computer, im not sure why, maybe i just cant read

@elee1766 elee1766 changed the title [WIP] #1496 Slice / Nil Equality Fix #1496 - Equality is incorrect when nil is used as the left argument of == Jan 1, 2023
@elee1766 elee1766 changed the title Fix #1496 - Equality is incorrect when nil is used as the left argument of == Fix issue #1496 - Equality is incorrect when nil is used as the left argument of == Jan 1, 2023
@elee1766
Copy link
Contributor Author

elee1766 commented Jan 1, 2023

#1496 is this how github works trying to tag the issue to this pr

im so sorry if someone is subscribed to this issue and im spamming your in box happy new year :)

@ldez ldez changed the title Fix issue #1496 - Equality is incorrect when nil is used as the left argument of == Equality is incorrect when nil is used as the left argument of == Jan 1, 2023
@mvertes mvertes self-requested a review March 22, 2023 10:28
@mvertes mvertes added this to the v0.15.x milestone Mar 22, 2023
Copy link
Member

@mvertes mvertes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this nice first submission. The fix you propose is globally correct, just a few details to change before we can merge this.

Thanks again.

interp/op.go Outdated Show resolved Hide resolved
_test/issue-1496.go Outdated Show resolved Hide resolved
_test/issue-1496.go Outdated Show resolved Hide resolved
@elee1766
Copy link
Contributor Author

awesome. i think i changed those things. let me know if there is anything else that needs to change.

Copy link
Member

@mvertes mvertes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

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

Successfully merging this pull request may close these issues.

nil and slice equality is incorrect
4 participants