Pregunta

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?

¿Fue útil?

Solución

Use the correct syntax:

trait BinaryConverter[T <: Expr { def lhs: Expr; def rhs: Expr }] extends Converter[Expr]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top