Open philiprbrenan opened 3 years ago
What behaviour might people otherwise be expecting? (The results of the examples do seem to follow the documentation for map
and reverse
.)
This is a general problem with two sources:
More warnings are helpful but I'm not sure exactly what we could warn about in this specific case.
The way I see it... the surprising factors are (1) when reverse
itself is in list context, and (2) when reverse
is passed only one argument. Such as these cases:
# a single string literal
($foo) = reverse("foo");
# a single scalar variable
%ridx = map { reverse($_) => 1 } ("foo", "bar");
When both (1) and (2) are satisfied, the list-reverse is essentially an no-op -- it does effectly nothing to the list, nor to the only element inside.
A warning message can probably be yield, saying: "reversing a list of one item would have no effect. Do you mean: scalar reverse($x) ?"
But there should probably be no warnings when an array of just one item is given to the list-reverse
@x = ("foo");
my @y = reverse(@x);
Please provide a compile time message explaining that
map{reverse $_}
does not behave as one might immediately expect as shown below: