Skip to content

Commit

Permalink
Hopefully fix all inheritance issues with set operators
Browse files Browse the repository at this point in the history
In response to #5190
  • Loading branch information
lizmat committed Feb 6, 2023
1 parent ee277f6 commit 586466e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core.c/set_addition.pm6
Expand Up @@ -87,7 +87,7 @@ multi sub infix:<(+)>(Baggy:D $a, QuantHash:D $b) {
nqp::if(
nqp::istype($b,Mixy),
nqp::if(nqp::istype($a,Bag),Mix,MixHash),
nqp::if(nqp::istype($a,Bag),Bag,BagHash)
nqp::if(nqp::istype($a,Bag),$a.WHAT,BagHash)
)
).SET-SELF(
nqp::if(
Expand Down
6 changes: 3 additions & 3 deletions src/core.c/set_difference.pm6
Expand Up @@ -12,15 +12,15 @@ multi sub infix:<(-)>(MixHash:D $a) { $a.Mix }
multi sub infix:<(-)>(Setty:D $a, Setty:D $b) {
(my $araw := $a.RAW-HASH) && nqp::elems($araw)
&& (my $braw := $b.RAW-HASH) && nqp::elems($braw)
?? nqp::create($a.Setty).SET-SELF( # both have elems
?? nqp::create($a.WHAT).SET-SELF( # both have elems
Rakudo::QuantHash.SUB-SET-FROM-SET($araw, $braw)
)
!! $a # no elems in a or b
}
multi sub infix:<(-)>(Setty:D $a, Map:D \b) {
nqp::if(
(my \araw := $a.RAW-HASH) && nqp::elems(araw),
nqp::create($a.Setty).SET-SELF( # elems in a
nqp::create($a.WHAT).SET-SELF( # elems in a
nqp::if(
nqp::elems(my \braw := nqp::getattr(nqp::decont(b),Map,'$!storage')),
Rakudo::QuantHash.SUB-MAP-FROM-SET(araw, b), # both have elems
Expand All @@ -36,7 +36,7 @@ multi sub infix:<(-)>(Setty:D $a, Iterable:D \b) {
Set.fail-iterator-cannot-be-lazy('set difference'),
nqp::if(
(my $raw := $a.RAW-HASH) && nqp::elems($raw),
nqp::create($a.Setty).SET-SELF( # elems in b
nqp::create($a.WHAT).SET-SELF( # elems in b
Rakudo::QuantHash.SUB-PAIRS-FROM-SET($raw, $iterator)
),
$a # no elems in b
Expand Down
4 changes: 3 additions & 1 deletion src/core.c/set_intersection.pm6
Expand Up @@ -33,7 +33,9 @@ multi sub infix:<(&)>(Setty:D $a, Setty:D $b) {
nqp::create($a.WHAT).SET-SELF($elems)
),
nqp::if( # one/neither has elems
nqp::istype($a,Set), set(), nqp::create(SetHash)
nqp::istype($a,Set),
nqp::if(nqp::eqaddr($a.WHAT,Set), set(), nqp::create($a.WHAT)),
nqp::create(SetHash)
)
)
}
Expand Down

0 comments on commit 586466e

Please sign in to comment.