On 26/08/2024 15:20, Stephen Reay wrote:
Hi,
Hi :)
I haven't followed the entire thread in depth so I apologise if this
was already answered, but I haven't noticed it being
mentioned/clarified yet.
Don't worry, you're right, this is an important topic that I was still
finalising in the past 48 hours and is still an omission from the RFC,
and as such we haven't discussed it on the list yet.
Can you clarify in the following, is the arm comparing against match's
default or the parameter's default? Or to put it another way, in the
second call, If `$arg` is 2, will the match error out due to an
unmatched subject, or will it pass 1 to `F`?
function F(int $foo =1) {}
F(match(default) {default =>default });
F(match($arg) {'a' =>0,default =>default });
Thank you for your (excellent) question. The answer is it will pass `1`,
and the reason is as follows.
`F(match(default) { default => default });` is interpreted as `match
(default expression) { default arm => default expression }`, therefore
the first and last `default`s will be substituted with the argument's
default, but not the middle one. However, that is only the case when the
default arm is written exactly as `default`.
You can turn the condition into an expression, in which case all three
will act as expressions and be substituted accordingly, e.g.
`F(match(default) { (int) default => default });`.
Since the default condition is now an expression, you can still have a
default arm in addition to this, e.g. the following would be valid:
F(match(default) {
(int) default => default,
default => default,
});
Whilst this is a curiosity, consider that passing match expressions
directly to arguments is something I personally have never witnessed and
that goes doubly for combining it with `default`. So, whilst it is
interesting to know, and important for the RFC to state the specific
semantics of this scenario, the practical applications are presumed slim
to none.
Cheers,
Bilge