# New Ticket Created by Zefram
# Please include the string: [perl #128943]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=128943 >
> Set.new("a", "b", "c").WHICH
Set|Str|a Str|b Str|c
> Set.new("a Str|b", "c").WHICH
Set|Str|a Str|b Str|c
> Set.new("a","b Str|c").WHICH
Set|Str|a Str|b Str|c
> Set.new("a Str|b Str|c").WHICH
Set|Str|a Str|b Str|c
These four sets are quite distinct (they have three different
cardinalities, for a start), but all get the same .WHICH string.
This happens because Set.WHICH concatenates its elements' .WHICH strings
with space separators, not bothering to quote the elements' .WHICH strings
or otherwise handle spaces in them. Presumably as a consequence, ===
actually says that the sets are identical:
> Set.new("a","b Str|c") === Set.new("a Str|b Str|c")
True
though the sets are actually iterable perfectly well, and === works fine
on sets that do not suffer a coincidence of .WHICH:
> Set.new("a Str|b Str|c").pairs.perl
("a Str|b Str|c" => Bool::True,).Seq
> Set.new("a","b Str|c").pairs.perl
(:a, "b Str|c" => Bool::True).Seq
> Set.new("a", "b") === Set.new("a", "b")
True
> Set.new("a", "b") === Set.new("a", "z")
False
In the above I've made the problem arise by deliberately constructing
strings containing spaces and parts of .WHICH syntax. But it can also
arise more innocently, by using elements of a class that puts spaces
into .WHICH itself, such as Set:
> Set.new(Set.new("a"), "b").WHICH
Set|Set|Str|a Str|b
> Set.new(Set.new("a", "b")).WHICH
Set|Set|Str|a Str|b
The discussion we're having on [perl #128931] about how .WHICH values
are meant to be distinct is relevant to this ticket. If I'm wrong about
the strings being intended to be different for distinct objects, then the
above bug report would be erroneous. But Set.WHICH doesn't incorporate
any part of its elements' .WHICH values other than the strings. So if
the strings are not sufficient to distinguish .WHICH values, Set.WHICH
is erroneous in relying on the strings to be distinct. Furthermore,
Set.WHICH doesn't actually return ObjAt objects, it returns plain strings
as Str objects (which may be a bug in its own right in any case).
-zefram