Why can't I make a Field definition more concise

14 views
Skip to first unread message

Dmitry Dobrynin

unread,
Mar 5, 2011, 7:19:18 AM3/5/11
to mongo-scala-driver
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.

Alexander Azarov

unread,
Mar 8, 2011, 12:45:33 PM3/8/11
to mongod...@googlegroups.com
Hi,

This seems to be Scala compiler bug indeed. Thank you!

Regards,
Alexander

Reply all
Reply to author
Forward
0 new messages