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

Comments

Projects
None yet
4 participants
@vrurg
Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link
Contributor

commented Jan 11, 2019

Fixed with ab8052d .

@lizmat lizmat added the tests needed label Jan 11, 2019

@vrurg

This comment has been minimized.

Copy link
Member Author

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.

@Altai-man

This comment has been minimized.

Copy link
Contributor

commented May 18, 2019

Tests proposed at perl6/roast#540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.