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

Strange behaviour of <<!=>> #4838

Closed
lizmat opened this issue Mar 31, 2022 · 3 comments
Closed

Strange behaviour of <<!=>> #4838

lizmat opened this issue Mar 31, 2022 · 3 comments

Comments

@lizmat
Copy link
Contributor

lizmat commented Mar 31, 2022

The Problem

From https://stackoverflow.com/questions/71690554/strange-behavior-of-a-hyperoperator

say 0 != 0;                 # False

my @a = 0, 0, 0;
say @a «==» @a;             # [True True True]
say @a «!=» @a;             # [True True True] <--- why?
say @a «!==» @a;            # [False False False]

Expected Behavior

say @a «!=» @a;             # [False False False]

Actual Behavior

say @a «!=» @a;             # [True True True] <--- why?

This is on Rakudo HEAD.

@lizmat
Copy link
Contributor Author

lizmat commented Mar 31, 2022

The problem appears to be in the codegen of «!=», as a direct call to METAOP_HYPER yields the correct result:

my @a = 0, 0, 0;
say METAOP_HYPER(&infix:<<!=>>)(@a,@a);  # [False False False]

This seems to be caused by the decision at https://github.com/rakudo/rakudo/blob/master/src/Perl6/Actions.nqp#L8121 to go for the given AST, rather than generating the proper call to &infix:<!=>.

Making that code always generate the call to &infix:<!=> makes the above code produce the correct result. But breaks spec tests, so there is more to it.

lizmat added a commit that referenced this issue Mar 31, 2022
In response to #4838

The applied fix feels hacky, but != *is* the only op that is
actually implemented as an op, and not as meta-handling applied
to an op.  Suggestions for better fix welcome!
lizmat added a commit that referenced this issue Mar 31, 2022
In response to #4838

The applied fix feels hacky, but != *is* the only op that is
actually implemented as an op, and not as meta-handling applied
to an op.  Suggestions for better fix welcome!
@lizmat
Copy link
Contributor Author

lizmat commented Mar 31, 2022

Turns out it was all wrong to begin with:

my @a = 1,2,3;
my @b = 4,5,6;
say @a >>!=<< @b;
say @a;  # [False False False]
say @b;  # [4 5 6]

So it actually created a meta-op using assignment. As can be seen with:

say (1,2) >>!=<< (3,4);
# Cannot modify an immutable Int (1)

@jnthn++ for noting. Fixed for now with the PR, should have special attention in the RakuAST branch in the future.

@lizmat lizmat closed this as completed Mar 31, 2022
@raiph
Copy link
Contributor

raiph commented Apr 1, 2022

cf Raku/old-issue-tracker#3322

melezhik added a commit to melezhik/r3tool that referenced this issue Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants