Closed
Description
Compiler version
3.1.1
Minimized code
class A
class B extends A
class C(b: B)
class D(b: B)(x: Int)
def c(b: B): B = b
def d(b: B)(x: Int): B = b
def f[S <: A, T](g: S => T): S => T = g
object Main {
def main(args: Array[String]): Unit =
// f(x => C(x)) // compiles
f(x => D(x)(0)) // doesn't compile
// f(x => c(x)) // compiles
f(x => d(x)(0)) // doesn't compile
}
Output
-- [E007] Type Mismatch Error: Test.scala:15:13 --------------------------------
15 | f(x => D(x)(0)) // doesn't compile
| ^
| Found: (x : A)
| Required: B
longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: Test.scala:17:13 --------------------------------
17 | f(x => d(x)(0)) // doesn't compile
| ^
| Found: (x : A)
| Required: B
longer explanation available when compiling with `-explain`
2 errors found
Expectation
The result of type inference should be (x: B)
becaue B
is a subclass of A
.
The program should compile.