Open RX14 opened 1 month ago
Oh dear, I think this parses as argsof(foo: yield("foo", bar: yield("bar")))
. I think perhaps this could be made a syntax error?
Wouldn't that potentially break existing code? It seems yield
without parentheses is a lot more common...
The behaviour is identical when calling a method instead of yield
:
def argsof(**args)
pp args
end
def yield_args(&)
argsof(
"foo": vield "foo",
"bar": vield "bar",
)
end
def yield_args2(&)
argsof(
"foo": vield("foo"),
"bar": vield("bar"),
)
end
def vield(arg, **args)
arg
end
yield_args { |x| x } # => {foo: "foo"}
yield_args2 { |x| x } # => {foo: "foo", bar: "bar"}
So while this looks certainly deceitful, it's syntactically sound and I don't think we can really change much about it without causing a major disruption.
Perhaps the formatter could help clarify the situation (for example by adding parentheses in ambiguous cases like this one).
However, the formatter actually fails on this code: expecting ), not
DELIMITER_START, , at :8:5
.
gives output
This should generate the same result for both calls, the second function argument cannot be lost.