2

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 Answers1

1

After googling a bit more (many hours), found that it's a known issue without fix.

https://github.com/playframework/playframework/issues/4598 is closed. https://github.com/slick/slick/issues/1382 is currently open.

I resolve this for now by using a custom code generator extended from slick's code generator that puts the case classes outside of the trait, according to: Custom Slick Codegen generate mapped case classes outside the `${container} trait`?