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