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

Smartmatch doesn't produce correct result on a run-time created class stored in a Scalar container #2602

Closed
vrurg opened this issue Jan 10, 2019 · 5 comments · Fixed by Raku/roast#540
Labels
smartmatch Smart matching with ~~ and .ACCEPTS methods tests needed Issue is generally resolved but tests were not written yet

Comments

@vrurg
Copy link
Member

vrurg commented Jan 10, 2019

The Problem

When a class is created with Metamodel::ClassHOW.new_type at run-time and stored in a scalar then smartmatching of an object created of this class with the containing scalar gives False.

Expected Behavior

Object must smartmatch its class.

Steps to Reproduce

This code:

my $a = Metamodel::ClassHOW.new_type(name => "A");
$a.^compose;
say $a.new.WHAT ~~ $a

prints False.

Environment

  • Operating system: macOS 10.14, Linux
  • Compiler version (perl6 -v): This is Rakudo version 2018.12 built on MoarVM version 2018.12
    Also tested against Perl6/MoarVM 2017.10
@lizmat
Copy link
Contributor

lizmat commented Jan 11, 2019

This appears to be related to the fact that you're putting the class definition into a scalar container by assigning to $a. If you bind to $a, it appears to work, for me at least.

my $a := Metamodel::ClassHOW.new_type(name => "A");
$a.^compose;
say $a.new.WHAT ~~ $a;    # True

@vrurg
Copy link
Member Author

vrurg commented Jan 11, 2019

Yes, it does. And this is the advise I gave on IRC and how I fixed similar issue in my own code. But the point is that this works:

my $a = class A { };
say $a.new ~~ $a;

And I see no reason why creation from the metamodel class must not work either. Here is another interesting variation of the code:

my $b = my $a := Metamodel::ClassHOW.new_type(name => "A"); 
$a.^compose; # Use of $b here changes the result
my $o = $a.new;
say $o ~~ $a; 
say $o ~~ $b

Depending on whether compose is called on $a or $b the resulting smartmatch gives either both True for $a, or both False for $b.

@lizmat
Copy link
Contributor

lizmat commented Jan 11, 2019

Fixed with ab8052d .

@lizmat lizmat added the tests needed Issue is generally resolved but tests were not written yet label Jan 11, 2019
@vrurg
Copy link
Member Author

vrurg commented Jan 11, 2019

Tested with rakudobrew, on moar-blead:

This is Rakudo version 2018.12-200-gd6b1bd2ae built on MoarVM version 2018.12-27-g9ce36b6a2

The reported buggy behavior is not reproducible on neither variant of the code I tried. Looks like it's fixed.

@lucasbuchala lucasbuchala added the smartmatch Smart matching with ~~ and .ACCEPTS methods label Mar 15, 2019
@Altai-man
Copy link
Member

Tests proposed at Raku/roast#540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smartmatch Smart matching with ~~ and .ACCEPTS methods tests needed Issue is generally resolved but tests were not written yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants