문제

I am given an abstract syntax tree which I cannot modify:

trait Expr
case class Equals(lhs: Expr, rhs: Expr) extends Expr
case class Plus(lhs: Expr, rhs: Expr) extends Expr
case class Id(value: String) extends Expr

Now I would like to create a converter, but this fails:

trait Converter[T <: Expr]
trait BinaryConverter[T <: Expr with { def lhs: Expr; def rhs: Expr }] extends Converter[Expr] {
  ???
}

But this does not work. If I remove Expr with, then it compiles. Same if I remove with { def lhs: Expr; def rhs: Expr }. What should I do to make it work?

도움이 되었습니까?

해결책

Use the correct syntax:

trait BinaryConverter[T <: Expr { def lhs: Expr; def rhs: Expr }] extends Converter[Expr]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top