Hi all
Some time ago I was playing with mongo-scala-driver and have found
some issue.
Why can't I make a Field definition more concise as follows:
class User(var name: String = null) extends MongoObject
object User extends MongoObjectShape[User] {
// there is no explicit definition of parameters of the "setter"
function.
val name = Field.scalar[String]("name", _.name, _.name = _)
def factory(dbo: DBObject) = Some(new User)
def * = oid :: name :: Nil
}
The compiler reports errors:
[ERROR] ...\src\test\scala\com\osinka\mongodb\User.scala:9: error:
missing parameter type for expanded function ((x$1) => x$
1.name)
[INFO] val name = Field.scalar[String]("name", _.name, _.name = _)
[INFO] ^
[ERROR] ...\src\test\scala\com\osinka\mongodb\User.scala:9: error:
missing parameter type for expanded function ((x$2, x$3) => x$
2.name =
x$3)
[INFO] val name = Field.scalar[String]("name", _.name, _.name = _)
[INFO] ^
[ERROR] ...\src\test\scala\com\osinka\mongodb\User.scala:9: error:
missing parameter type for expanded function ((x$2: <error>, x$3) => x
$
2.name = x$3)
[INFO] val name = Field.scalar[String]("name", _.name, _.name = _)
[INFO] ^
[ERROR] three errors found
When I have added method
def scalar[A](fieldName: String, getter: T => A, setter: (T, A) =>
Unit) = new ScalarField[A](fieldName, getter, Some(setter))
into ShapeFields my code was compiled successfully.
I think this is the scala compiler issue. So please consider to move
all helper methods from Field object to ShapeFields trait.