trait Base {
type M
}
final class Impl extends Base {
type M = Int
}
object Test {
def toRep[T, S <: Base { type M = T }](s: S): T = ???
toRep(new Impl)
}
Problem
Trying to compile the code above it fails with
refinement_inference.scala:12: error: inferred type arguments [Nothing,Impl] do not conform to method toRep's type parameter bounds [T,S <: Base{type M = T}]
toRep(new Impl)
^
refinement_inference.scala:12: error: type mismatch;
found : Impl
required: S
toRep(new Impl)
^
two errors found
so the compiler failed to infer the type of T correctly.
More info
Changing the def of toRep slightly so
def toRep[T, S <: Base](s: S { type M = T }): T = ???
makes it infer the correct type and the code compiles.
Reproduction steps
Scala version: 2.13 and 2.12 but works in scala 3
Problem
Trying to compile the code above it fails with
so the compiler failed to infer the type of
T
correctly.More info
Changing the def of
toRep
slightly somakes it infer the correct type and the code compiles.