Open noresttherein opened 11 months ago
scalac -Vprint
shows how the default args are elaborated:
<synthetic> def copy$default$1[N]: Array[Nut] = Squirrel.this.nuts
<synthetic> def copy$default$1[S]: Array[S] = castingUtil.safeCasting[Array[Seed]](Hamster.this.seeds).cast[Array[Seed], Array[S]]
The RHS is what you wrote, and the result type is inferred from that (as usual) and not the type of the parameter for which it is a default.
Also
scala> implicitly[Array[String] <:< Array[AnyRef]]
^
error: Cannot prove that Array[String] <:< Array[AnyRef].
Your error here is for a tweaked version of the posted source.
Separately, there are issues with default args and how they are type checked. I think Scala 3 intends to explore different implementations eventually.
I think Scala 3 intends to explore different implementations eventually
reference: https://contributors.scala-lang.org/t/better-default-arguments/6034
Reproduction steps
Scala version: 2.13.11
Problem
I can't even put it into words, but apparently
nuts
/seeds
have their type parameters mistyped in this context to the method type parameter, rather than owning class's type parameter.Also, removing
val
keywords and leaving the properties as pure fields still work, that is are legal for use as default parameters. I don't report it, because it probably is a feature.