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

Regression: No such method 'op_props' for invocant of type 'Block' #5221

Open
cfa opened this issue Feb 27, 2023 · 4 comments
Open

Regression: No such method 'op_props' for invocant of type 'Block' #5221

cfa opened this issue Feb 27, 2023 · 4 comments

Comments

@cfa
Copy link

cfa commented Feb 27, 2023

The Problem

The following example from the documentation fails to compile in 2023.02 (and the current HEAD),

multi sub infix:<||=>($a, $b) is equiv(&infix:<+=>) { $a || $b }
 
my $foo = 0;
$foo ||= 1;
say $foo; # OUTPUT: 1 

with the following error

===SORRY!=== Error while compiling /Users/cfa/tmp/fail.raku
No such method 'op_props' for invocant of type 'Block'
at /Users/cfa/tmp/fail.raku:1

Expected Behavior

Compilation without error.

Relatedly, the documentation expects $foo to be 1 but bisection indicates that when this compiled (≤2022.12), the result was consistently 0.

A few relevant bisection logs,

Environment

  • Operating system: macOS 13.2.1
  • Compiler version (perl6 -v or raku -v): 2023.12
@thundergnat
Copy link
Contributor

Seems to me there are two separate issues in play with this.

First: += is a synthetic operator. It is not explicitly present in the grammar so the precedence level needs to be derived separately. That seems to have broken with commit a7ccfc6 "Move .prec from Routine to Code " That's definitely a regression.

Second: I don't see how that ever would have returned 1. Since the equal sign is part of the operator, there is no synthetic assignment operator, and there is no assignment within the operator routine, so the value 1 would never have been assigned to $foo. It will still be 0. And it is.

Leaving aside the problem with the precedence of synthetic operators, (just use <+> for now), I would expect that to be written something like:

multi sub infix:<||=>($a is raw, $b) is equiv(&infix:<+>) { $a = ($a || $b) }

my $foo = 0;
$foo ||= 1;
say $foo; # OUTPUT: 1

So regression and bad example.

@cfa
Copy link
Author

cfa commented Feb 28, 2023

Thanks @thundergnat.

Regarding the example, should the documentation be updated to use your amended version? If so, would you like to make the change?

@2colours
Copy link
Contributor

That example is really bad anyway - ||= does exist by default, what value does it add to re-implement it badly? That's surely not "making your own operator"... I'd change that (and if nobody objects, I will) to something like |-| for distance (absolute value of difference).

By the way: if a7ccfc6 broke the precedence, how come the regression only happened more than 5 years later? That's surely not the whole story - although it's good to know that apparently the issue affects precedence derivation of synthetic operators, thank you.

@cfa
Copy link
Author

cfa commented Feb 28, 2023

Thanks @2colours.

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

3 participants