I use scala 2.11.2. This is part of my function:
import scala.reflect.runtime.universe._
p => p.filter(p => typeOf[p.type] != typeOf[Nothing]).flatMap {
case Some(profile) => {
...
env.userService.save(profile.copy(passwordInfo = Some(hashed)),...) //<---------error here
}
case _ => ...
}
the compile error is:
PasswordReset.scala:120: value copy is not a member of Nothing
[error] env.userService.save(profile.copy(passwordI
nfo = Some(hashed)), SaveMode.PasswordChange);
[error] ^
I think I use filter phase filter the Nothing type, but why it is still give me type Nothing error. I do not want to:
profile.getDefault().copy(...)
Because I really need to copy the profile instead of to copy the default value, if profile is Nothing just delete it. How to do it?
Filter doesn't change types.
Option[A]
comes in,Option[A]
goes out.You're suggesting that the runtime check in your filter function should instruct the compiler to accept that your type param is not Nothing, but that's not how it works.
If Nothing is inferred, then Nothing is what you get.
You want to keep the compiler from inferring Nothing somewhere. Sometimes it's necessary to provide explicit type args to do that:
compare to
But it's also possible you could express your code differently.