Skip to content

Commit

Permalink
Fix for issue with Z / X with set operators (#3950)
Browse files Browse the repository at this point in the history
* Let the multi-fallback handle Any case as well

A good night of sleep revealed the solution: using the +@p signature
instead of the **@p signature on the fallback, should fix the issue
found with Z and X using set operators that don't return a Bool.

This caused one complication: the Any candidates of these set operators
are apparently narrower than the +@p candidates, so these are now
removed and the logic for handling a single value is now handled by
the +@p fallback candidates.
  • Loading branch information
lizmat committed Oct 14, 2020
1 parent e0e24a8 commit 338c743
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/core.c/set_addition.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ multi sub infix:<(+)>() { bag() }
multi sub infix:<(+)>(Bag:D \a) { a }
multi sub infix:<(+)>(Mix:D \a) { a }
multi sub infix:<(+)>(MixHash:D \a) { a.Mix }
multi sub infix:<(+)>(Any \a) { a.Bag }

multi sub infix:<(+)>(Setty:D \a, QuantHash:D \b) {
nqp::if(
Expand Down Expand Up @@ -160,10 +159,15 @@ multi sub infix:<(+)>(Any \a, Any \b) {
)
}

multi sub infix:<(+)>(**@p) {
my $result = @p.shift;
$result = $result (+) @p.shift while @p;
$result
multi sub infix:<(+)>(+@p) { # also Any
my $result := @p.shift;
if @p {
$result := $result (+) @p.shift while @p;
$result
}
else {
$result.Bag
}
}

# U+228E MULTISET UNION
Expand Down
3 changes: 1 addition & 2 deletions src/core.c/set_difference.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ multi sub infix:<(-)>(QuantHash:D \a) { a } # Set/Bag/Mix
multi sub infix:<(-)>(SetHash:D \a) { a.Set }
multi sub infix:<(-)>(BagHash:D \a) { a.Bag }
multi sub infix:<(-)>(MixHash:D \a) { a.Mix }
multi sub infix:<(-)>(Any \a) { a.Set } # also for Iterable/Map

multi sub infix:<(-)>(Setty:D \a, Setty:D \b) {
nqp::if(
Expand Down Expand Up @@ -92,7 +91,7 @@ multi sub infix:<(-)>(Any $, Failure:D \b) { b.throw }
multi sub infix:<(-)>(Failure:D \a, Any $) { a.throw }
multi sub infix:<(-)>(Any \a, Any \b) { infix:<(-)>(a.Set,b.Set) }

multi sub infix:<(-)>(**@p) {
multi sub infix:<(-)>(+@p) { # also Any

sub subtract(Mu \elems, Mu \iter, \clone, \value --> Nil) {
nqp::stmts(
Expand Down
14 changes: 9 additions & 5 deletions src/core.c/set_intersection.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
proto sub infix:<(&)>(|) is pure {*}
multi sub infix:<(&)>() { set() }
multi sub infix:<(&)>(QuantHash:D \a) { a } # Set/Bag/Mix
multi sub infix:<(&)>(Any \a) { a.Set } # also for Iterable/Map

multi sub infix:<(&)>(Setty:D \a, Setty:D \b) {
nqp::if(
Expand Down Expand Up @@ -147,10 +146,15 @@ multi sub infix:<(&)>(Any \a, Any \b) {
!! a.Set (&) b
}

multi sub infix:<(&)>(**@p) {
my $result = @p.shift;
$result = $result (&) @p.shift while @p;
$result
multi sub infix:<(&)>(+@p) { # also Any
my $result := @p.shift;
if @p {
$result := $result (&) @p.shift while @p;
$result
}
else {
$result.Set
}
}

# U+2229 INTERSECTION
Expand Down
14 changes: 9 additions & 5 deletions src/core.c/set_multiply.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ proto sub infix:<(.)>(|) is pure {*}
multi sub infix:<(.)>() { bag() }
multi sub infix:<(.)>(Setty:D \a) { a.Baggy }
multi sub infix:<(.)>(Baggy:D \a) { a } # also Mixy
multi sub infix:<(.)>(Any \a) { a.Bag }

multi sub infix:<(.)>(Setty:D \a, Setty:D \b) {
nqp::if(
Expand Down Expand Up @@ -63,10 +62,15 @@ multi sub infix:<(.)>(Any \a, Any \b) {
)
}

multi sub infix:<(.)>(**@p) {
my $result = @p.shift;
$result = $result (.) @p.shift while @p;
$result
multi sub infix:<(.)>(+@p) { # also Any
my $result := @p.shift;
if @p {
$result := $result (.) @p.shift while @p;
$result
}
else {
$result.Bag
}
}

# U+228D MULTISET MULTIPLICATION
Expand Down
3 changes: 1 addition & 2 deletions src/core.c/set_symmetric_difference.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
proto sub infix:<(^)>(|) is pure {*}
multi sub infix:<(^)>() { set() }
multi sub infix:<(^)>(QuantHash:D \a) { a } # Set/Bag/Mix
multi sub infix:<(^)>(Any \a) { a.Set } # also for Iterable/Map

multi sub infix:<(^)>(Setty:D \a, Setty:D \b) {
nqp::if(
Expand Down Expand Up @@ -225,7 +224,7 @@ multi sub infix:<(^)>(Any \a, Any \b) {
!! a.Set (^) b.Set
}

multi sub infix:<(^)>(**@p) {
multi sub infix:<(^)>(+@p) { # also Any

# positions / size in minmax info
my constant COUNT = 0;
Expand Down
14 changes: 9 additions & 5 deletions src/core.c/set_union.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
proto sub infix:<(|)>(|) is pure {*}
multi sub infix:<(|)>() { set() }
multi sub infix:<(|)>(QuantHash:D \a) { a } # Set/Bag/Mix
multi sub infix:<(|)>(Any \a) { a.Set } # also for Iterable/Map

multi sub infix:<(|)>(Setty:D \a, Setty:D \b) {
nqp::if(
Expand Down Expand Up @@ -172,10 +171,15 @@ multi sub infix:<(|)>(Any \a, Any \b) {
!! a.Set (|) b
}

multi sub infix:<(|)>(**@p) {
my $result = @p.shift;
$result = $result (|) @p.shift while @p;
$result
multi sub infix:<(|)>(+@p) { # also Any
my $result := @p.shift;
if @p {
$result := $result (|) @p.shift while @p;
$result
}
else {
$result.Set
}
}

# U+222A UNION
Expand Down

0 comments on commit 338c743

Please sign in to comment.