“Parameter type in structural refinement may not refer to an abstract type defined outside that refinement”

前端 未结 2 1361
深忆病人
深忆病人 2020-12-03 13:29

When I compile:

object Test extends App {
  implicit def pimp[V](xs: Seq[V]) = new {
    def dummy(x: V) = x
  }
}                                                    


        
2条回答
  •  醉话见心
    2020-12-03 14:14

    Discovered the problem shortly after posting this: I have to define a named class instead of using an anonymous class. (Still would love to hear a better explanation of the reasoning though.)

    object Test extends App {
      case class G[V](xs: Seq[V]) {
        def dummy(x: V) = x
      }
      implicit def pimp[V](xs: Seq[V]) = G(xs)
    }                                                                                                                                                                                                              
    

    works.

提交回复
热议问题