Heiko Seeberger
unread,Oct 20, 2010, 1:03:01 PM10/20/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongo-scala-driver
Hi,
Any ideas why the following code won't compile?
package wontcompile
import java.util.Locale
import com.osinka.mongodb.shape. {ObjectIn, MongoObjectShape}
import com.mongodb.DBObject
import com.osinka.mongodb.MongoObject
trait AttrOptionIn[A] extends ObjectIn[AttrOption, A] {
lazy val value = Field.scalar("value", _.value)
lazy val name = new EmbeddedField[I18nName]("name", _.name, None)
with I18nNameIn[AttrOption]
lazy val * = value :: name :: Nil
def factory(dbo: DBObject): Option[AttrOption] =
for {
value(v) <- Some(dbo)
name(n) <- Some(dbo)
} yield AttrOption(v, null )
}
case class AttrOption(value: Int, name: I18nName) extends MongoObject
trait I18nNameIn[A] extends ObjectIn[I18nName, A] {
lazy val de = Field.optional("de", _.de)
lazy val en = Field.optional("en", _.de)
lazy val fr = Field.optional("fr", _.de)
lazy val it = Field.optional("it", _.de)
lazy val * = de :: en :: fr :: it :: Nil
def factory(dbo: DBObject): Option[I18nName] =
for {
de(d) <- Some(dbo)
en(e) <- Some(dbo)
fr(f) <- Some(dbo)
it(i) <- Some(dbo)
} yield I18nName(Option(d), Option(e), Option(f), Option(i))
}
object I18nName extends MongoObjectShape[I18nName] with
I18nNameIn[I18nName]
case class I18nName(
de: Option[String] = None,
en: Option[String] = None,
fr: Option[String] = None,
it: Option[String] = None) extends MongoObject {
def name(implicit locale: Locale): String = {
import Locale._
locale match {
case GERMAN => de getOrElse mongoOID.toString
case ENGLISH => de getOrElse mongoOID.toString
case FRENCH => de getOrElse mongoOID.toString
case ITALIAN => de getOrElse mongoOID.toString
case _ => mongoOID.toString
}
}
}
This is the error message:
[error] /Users/hseeberger/projects/ism/src/test/scala/
wontcompile.scala:12: illegal inheritance;
[error] self-type
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName] with
wontcompile.I18nNameIn[wontcompile.AttrOption] does not conform to
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName]'s selftype
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName] with
AttrOptionIn.this.MongoField[wontcompile.I18nName] with
com.osinka.mongodb.shape.ObjectIn[wontcompile.I18nName,A]
[error] lazy val name = new EmbeddedField[I18nName]("name", _.name,
None) with I18nNameIn[AttrOption]
[error] ^
Thanks,
Heiko