2

Can someone help me to understand what is wrong with the code below? The problem is inside the "join" method - I am not able to set "state" field. Error message is -

No implicit view available from code.model.Membership.MembershipState.Val => _14.MembershipState.Value.
[error]         create.member(user).group(group).state(MembershipState.Accepted).save
[error]                                                       ^
[error] one error found
[error] (compile:compile) Compilation failed

What does _14 mean? I tried similar thing with MappedGender and it works as expected, so why MappedEnum fails?

scala 2.10 lift 2.5

Thanks

package code
package model

import net.liftweb.mapper._
import net.liftweb.util._
import net.liftweb.common._


class Membership extends LongKeyedMapper[Membership] with IdPK {
  def getSingleton = Membership


  object MembershipState extends Enumeration {
   val Requested = new Val(1, "Requested")
   val Accepted = new Val(2, "Accepted")
   val Denied = new Val(3, "Denied")
  }

  object state extends MappedEnum(this, MembershipState)
  {
    override def defaultValue = MembershipState.Requested
  }

  object member extends MappedLongForeignKey(this, User) {
    override def dbIndexed_? = true
  }


  object group extends MappedLongForeignKey(this, Group) {    
    override def dbIndexed_? = true
  }

}

object Membership extends Membership with LongKeyedMetaMapper[Membership] {
    def join (user : User, group : Group) = {       
        create.member(user).group(group).state(MembershipState.Accepted).save
    } 
}
4

2 回答 2

1

_14 means a compiler-generated intermediate anonymous value. In other words, the compiler doesn't know how to express the type it's looking in a better way.

But if you look past that, you see the compiler is looking for a conversion from [...].Val to [...].Value. I would guess that changing

val Requested = new Val(1, "Requested")

to

val Requested = Value(1, "Requested")

would fix the error.

(I'm curious where you picked up the "new Val" style?)

What's strange is that Val actually extends Value. So if the outer type was known correctly (not inferred to the odd _14) Val vs. Value wouldn't be a problem. The issue here is that Lift from some reason defines the setters to take the now-deprecated view bound syntax. Perhaps this causes the compiler, rather than going in a straight line and trying to fit the input type into the expected type, instead to start from both ends, defining the starting type and the required type, and then start searching for an implicit view function that can reconcile the two.

于 2013-06-17T03:55:52.797 回答
1

尝试将您的MembershipState枚举移到MembershipClass. 在尝试此操作之前,我遇到了与您相同的错误。不知道为什么,但是在我这样做之后编译的代码。

于 2013-06-13T22:15:51.503 回答