play-json OWrites for a class in trait which is implemented by an object of same name

Viewed 78

When slick generates code, it's something like this (sample1/Tables.scala):

package sample1

object Tables extends {
  val profile = ???
} with Tables

trait Tables {
  case class Class1Row(num: Int)
}

I just want a dump of db objects using play-json so I need OWrites (in sample1/X.scala):

package sample1

import play.api.libs.json.{Json, Writes}

object X {
  implicit val class1Writes: Writes[Tables.Class1Row] = Json.writes[Tables.Class1Row]
}

When compiling, it complains:

sample1/X.scala:6:68
type mismatch;
 found   : Tables.this.Class1Row => Option[Int]
 required: sample1.Tables.Class1Row => Option[Int]
  implicit val class1Writes: Writes[Tables.Class1Row] = Json.writes[Tables.Class1Row]

Why is there a compilation issue when I have already specified the same type on both side of val assignment?

1 Answers
Related