-
Notifications
You must be signed in to change notification settings - Fork 22
False positive compile type mismatch error for 2.13.x and 2.12.x #13164
Copy link
Copy link
Open
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)infer
Milestone
Description
Reproduction steps
Scala version: 2.13.x and 2.12.x (for scala 3 - it's OK)
Scastie snippet - https://scastie.scala-lang.org/LMQAZoz8SWqdVxy9DTrP3w
//> using scala 2.13.18
object Main {
trait Capability
object Capability {
object Cap1 extends Capability
object Cap2 extends Capability
}
type Cap1 = Capability.Cap1.type
type Cap2 = Capability.Cap2.type
trait Bar[BarCap <: Capability]
trait Foo[FooCap] {
def add[Cap <: Capability](bar: Bar[Cap]): Foo[Cap with FooCap] = ???
}
def t1: Bar[Cap1] = ???
def t2: Bar[Cap2] = ???
def base: Foo[Any] = ???
// Compiles - OK
val result1: Foo[Cap2 with Cap1 with Any] = {
val inner = base
.add(t1)
.add(t2)
inner
}
//Compile error: type mismatch;
//found : Bar[Cap2]
// (which expands to) Bar[Capability.Cap2.type]
// required: Bar[Capability.Cap1.type with Capability.Cap2.type]
//Note: Cap2 >: Capability.Cap1.type with Capability.Cap2.type, but trait Bar is invariant in type BarCap.
//You may wish to define BarCap as -BarCap instead. (SLS 4.5)
val result2: Foo[Cap2 with Cap1 with Any] = {
base
.add(t1)
.add(t2)
}
}Problem
I believe that result2 should compile too. In short, we get the case - this compiles:
val foo: SomeType = {
val bar = expr
bar
}
But that not
val foo: SomeType =
expr
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)infer