error: polymorphic expression with default arguments
- by 0__
This following bugs me:
trait Foo[ A ]
class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty )
This yields
<console>:8: error: polymorphic expression cannot be instantiated to expected type;
found : [A]scala.collection.immutable.Set[A]
required: Set[Foo[?]]
class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty )
^
It is quite annoying that I have to repeat the type parameter in Set.empty. Why does the type inference fail with this default argument? The following works:
class Bar[ A ]( set: Set[ Foo[ A ]] = { Set.empty: Set[ Foo[ A ]]})
Please note that this has nothing to do with Set in particular:
case class Hallo[ A ]()
class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply ) // nope
Strangely not only this works:
class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply[ A ])
...but also this:
class Bar[ A ]( hallo: Hallo[ A ] = Hallo() ) // ???