You’re not allowed to name unnamed things, per the explainer for named tuples.
To address Odd compile error for `indexOf` with named arg · Issue #27054 · scala/scala3 · GitHub , Backquoted named args are positional for Java API by som-snytt · Pull Request #27088 · scala/scala3 · GitHub proposes that backticked names allow providing “documentary” names. The arguments are ordinary positional arguments.
It further suggests that, for uniformity, backticked named args are always positional. The names would be checked if parameter names are available.
My pet use case would be to ensure canonical order and avoid rewriting:
@deprecated(`message` = "Unusable", `since` = "3.0")
Currently, I name only since, since it reads naturally in that order. (I don’t remember whether annotations still care about swapped arguments.)
As a consequence, one could not reorder an argument with a name that requires backticks already.
Is it worth the small effort?
I’m not sure what you are proposing
Are you saying we should make
def foo(`x`: Int)
work like the following python code
def foo(x, /)
?
so the problem lies on the compiler dropping/omitting the param names from Java-defined ones. even though Metals seems to show the names (in dropdown autocompletes) for some reason.
alternatively a (theoretical) compiler flag like -language:javadefined-namedparams (suggestions welcome) could well make it.
For example,
def s = "abacus"
def i = s.indexOf('a', `fromIndex` = 1)
where the parameters are not named, for reasons.
Or, adjusting the example from the doc for named tuples,
val f: Int => T
f(2) // OK
f(index = 2) // Not OK
f(`index` = 2) // OK
f(`param` = 2) // also OK, as the name is documentary and unchecked
This is only about the call site.
The idiom for declaring a parameter unnameable is
def f(@deprecatedName("x") x: Int) = x + 1
That merely warns for f(x = 42).
If I write
def repeat(`s or null`: String | Null, n: Int) = if s != null s * n else s
then I can’t write
repeat(n = 42, `s or null` = "hello, world")
No one has suggested borrowing pattern syntax to bind the name:
repeat(n @ 42, `s or null` @ "hello, world")
My shoulders are already sagging a bit from this pre-pre-SIP, but I am reinvigorated when I contemplate:
s.indexOf('a', /*fromIndex =*/ 1)