Closed tindzk closed 6 years ago
Here is another failure case where a class cannot be initialised when a parameter is omitted:
@ case class Wrap[T <: Singleton](a: String with T,
b: Map[String, Any] = Map.empty,
c: List[String] = List.empty)
defined class Wrap
@
@ Wrap("div")
res2: Wrap[div] = Wrap("div", Map(), List())
@ Wrap("div", c = List.empty)
cmd3.sc:1: type mismatch;
found : String
required: String with "div"
Error occurred in an application involving default arguments.
val res3 = Wrap("div", c = List.empty)
^
Compilation Failed
Similar behavior in dotty: https://scastie.scala-lang.org/Yv0JU7ETRMWAHFa4zKc5RQ
Why not write?
case class Tag[T <: String with Singleton](a: T)
The issue is that a
is being widened on access, and this interferes with copy
. I think this should probably be fixed in the synthesis of copy
, but it can be worked around by preventing the widening more generally,
scala> case class Tag[T <: String with Singleton](a: T {})
defined class Tag
scala> Tag("a").copy()
res0: Tag["a"] = Tag(a)
There seems to be a problem with handling default parameters that are singleton values:
This works as expected: