r.piesnikowski
r.piesnikowski

Reputation: 2961

Playframework, scala case class and property not found

I've got very strange behaviour when I run playframework in scala. I used anorm as database access layer thus I've started doing some code and I saw very strange scala compiler behavoiur.

This is code which is working:

case class P_Page_Control(Control_ID:Int,
                      Client_ID:String,
                      cContent: String,
                      Page_ID: Int,
                      Language_ID: Int,
                      InsertTime: Date,
                      ChangeTime: Option[Date],
                      IsDeleted: Boolean)

and:

object P_Page_Control {  val parser = {
  get[Int]("Control_ID") ~
  get[String]("Client_ID") ~
  get[String]("Content") ~
  get[Int]("Page_ID") ~
  get[Int]("Language_ID") ~
  get[Date]("InsertTime") ~
  get[Option[Date]]("ChangeTime") ~
  get[Boolean]("IsDeleted") map {
    case a ~ b ~ c ~ d ~ e ~ f ~ g ~ h =>
      P_Page_Control(a, b, c, d, e, f, g, h)
  }}}

For this moment no compilation error. Works fine. But when I change property name I got errors:

object P_Page_Control {  val parser = {
  get[Int]("Control_ID") ~
  get[String]("Client_ID") ~
  get[String]("Content") ~
  get[Int]("Page_ID") ~
  get[Int]("Language_ID") ~
  get[Date]("InsertTime") ~
  get[Option[Date]]("ChangeTime") ~
  get[Boolean]("IsDeleted") map {
    case A_B ~ b ~ c ~ d ~ e ~ f ~ g ~ h =>
      P_Page_Control(A_B, b, c, d, e, f, g, h)
  }}}

As I'm a totally new to Scala I thought _ is some magic keyword or other magic stuff.

So I changed property name to aBB_AccAd but there was no compilation errors.

ooops...

Next funny thing: I renamed this to AAbbdddsadasdasAAFFFFeeee and I saw again compilation errors. So what motivates Scala to throw compilation error for some set of literals?

Is this a bug or feature ? :-)

Compilation error

Upvotes: 2

Views: 373

Answers (1)

Kim Stebel
Kim Stebel

Reputation: 42047

Names in patterns, which start with a capital letter, are interpreted as variable or object names that refer to an extractor (an object with an unapply or unapplySeq method). Since you haven't declared such a variable or object, Scala can't find it and throws an error.

Upvotes: 3

Related Questions