Function with two underscore parameters and a default — should this compile?

It is not a “bug” because it is the intended design: call-site arguments are assigned greedily to the next function parameter with a matching label. Here are a couple of older threads about the topic:

Rationale for Swift’s overload resolution?
Ordering Of Unnamed Parameters & Parameters With Default Values

It would technically be possible to change the design. There exists an algorithm that can match “as greedily as possible” while allowing defaulted parameters to be skipped if necessary. The “obvious” ways to do so take O(mn) time, where m is the number of arguments at the call-site and n is the number of parameters in a candidate function. I have heard that a quasilinear algorithm exists as well.

This is related to the longest common subsequence problem. I can’t remember the name of the exact problem off the top of my head. It is essentially a test for “is A (the call-site argument labels) a subsequence of B (the declaration-site argument labels), which contains subsequence C (the non-defaulted labels), plus some fiddly stuff about trailing closures.

It’s a bit more tricky than that though, because the positioning of C within A must be “compatible” with the positioning of C within B.

2 Likes