Strange behavior of a hyperoperator

Viewed 108

I found out this 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]

The != infix operator is defined here as equivalent to !== while apparently it's not, at least when used in a hyperoperator.

The problem seems to be related to the specific value (zero), since using a different value returns the expected result. Besides, using 0 but True works fine:

@a = 0 but True, 0 but True, 0 but True;
say @a «!=» @a;             # [False False False]

I'm using Rakudo 2022.03.

Is this a bug or something I cannot grasp?

1 Answers

It most definitely is a bug, as this:

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

gives the correct result. However, what gets passed to HYPER is not the &infix:<<!=>>, but a code block that apparently wraps it (incorrectly).

Investigating further, but please, yes, this is a bug and as such should be reported :-)

EDIT: https://github.com/rakudo/rakudo/issues/4838

EDIT: https://github.com/rakudo/rakudo/pull/4839 fixes it, but am unsure about the way it fixes it :-)

EDIT: Fix has been approved by jnthn, merged. Will be in 2022.04. Thanks for noting!

Related