Closed
Description
The following code snippet does not compile with Dotty but does with Scalac.
object Test {
def second[A, B <: A](foo: A, bar: B): B = bar
def expectString(s: String) = s
def test = {
second(Set.empty[String], Set.empty) map expectString
}
}
It fails with the following error:
./tests/allan/Experiment.scala:7: error: type mismatch:
found : Any(s)
required: String
second(Set.empty[String], Set.empty) map expectString
^
It also fails to compile if second
is defined as follow:
def second[A, B >: A](foo: A, bar: B): B = bar
with the following error:
./tests/allan/Experiment.scala:7: error: type mismatch:
found : (scala.collection.immutable.Set[String] | scala.collection.immutable.Set[Any]) @UnsafeNonvariant#A(s)
required: String
second(Set.empty[String], Set.empty) map expectString
^
Note that it does compile with second
applied on List
instead of Set
:
second(List.empty[String], List.empty) map expectString
Not sure if it is a duplicate of #998