-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use Equal[_] with case object #735
Comments
I think we can generalize this issue to that refineMV and refined.auto don't handle singleton objects, just literal singleton types (at least that's what I think it is). |
In fact, it doesn't work on literal singleton types either, just inline literals :/ |
@kubukoz Could you provide an example? The example below works as expected and is not using an "inline literal". scala> val s = "Hello"
s: String = Hello
scala> refineMV[Equal[s.type]]("World")
<console>:37: error: Predicate failed: (World == Hello).
refineMV[Equal[s.type]]("World")
^ |
@bwiercinski scala> refineV[ValidStatus](Status.A: Status)
res5: Either[String,eu.timepit.refined.api.Refined[Status,ValidStatus]] = Right(A)
scala> refineV[ValidStatus](Status.C: Status)
res6: Either[String,eu.timepit.refined.api.Refined[Status,ValidStatus]] = Left(Predicate failed: oneOf((C == A), (C == B), false).) It will never work with |
@fthomas but As for the literal singletons: type X = String Refined Equal["foo"]
@ val a: X = "foo"
a: X = foo
@ val b: "foo" = "foo"
b: String = "foo"
@ val c: X = b
cmd11.sc:1: compile-time refinement only works with literals
val c: X = b
^
Compilation Failed which is basically the opposite way (the literal is the value I want to refine, and in your example it's the type to refine to) |
Yes, but |
Could we inspect the type of I tried doing this myself but I'm not that familiar with the scala-reflect API and couldn't figure that out soon enough... |
Oh, I see. That would probably be impossible in the general case (some validations will really require an instance). However, for literal singleton types we could use the name of the type as the value. |
You're right. But I wouldn't recommend changing |
I want to achieve:
and i get
when i changed to
i got
refineV
also not workingThe text was updated successfully, but these errors were encountered: