Question

Why am I getting an error while compiling this snippet?

trait ID[R <: Record[R] with KeyedRecord[Long]] {

  this: R =>

  val idField = new LongField(this)
}

ERROR:

inferred type arguments [ID[R] with R] do not conform to class LongField's
type parameter bounds [OwnerType <: net.liftweb.record.Record[OwnerType]]

How can I fix this?


LongField definition:

class LongField[OwnerType <: Record[OwnerType]](rec: OwnerType)
  extends Field[Long, OwnerType] with MandatoryTypedField[Long] with LongTypedField {
Was it helpful?

Solution

Convert

val idField = new LongField(this)

to

val idField = new LongField[R](this)

If you do not specify the type R, then the LongField cannot check if the type is co-variant to Record[OwnerType] or not. Explicitly mentioning it should solve the purpose.

PS: I do not know the other class declaration to re-confirm, but the below declaration works:

case class Record[R]
class KeyedRecord[R] extends Record[R]
class LongField[OwnerType <: Record[OwnerType]](rec: OwnerType)
trait ID[R <: Record[R] with KeyedRecord[Long]] {
  this: R =>
  val idField = new LongField[R](this)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top