How to infer the right type parameter from a projection type?

后端 未结 2 1798
青春惊慌失措
青春惊慌失措 2021-02-08 04:21

I have some troubles having Scala to infer the right type from a type projection.

Consider the following:

trait Foo {
  type X
}

trait Bar extends Foo {         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 04:47

    The program compiles by adding this implicit conversion in the context:

    implicit def f(x: Bar#X): Foo#X = x
    

    As this implicit conversion is correct for any F <: Foo, I wonder why the compiler does not do that by itself.

提交回复
热议问题