Frage

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?

War es hilfreich?

Lösung

Use the correct syntax:

trait BinaryConverter[T <: Expr { def lhs: Expr; def rhs: Expr }] extends Converter[Expr]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top