Feature request: Add runtime exception check instead of error "compile-time refinement only works with literals"
See original GitHub issueHi, I’m posting this feature request after a small e-mail exchange with @fthomas
The code
for (i <- -1 to 3)
println(refineMV[Positive](i))
currently results in compile-time refinement only works with literals error.
I suggest that instead this will result in a runtime check, meaning four possible cases:
-
Compile time check pass for literal (no runtime check required)
println(refineMV[Positive](1))
Prints outs: 1
-
Compile time check fail for literal
println(refineMV[Positive](0))
-
Compile time check could not run, so running runtime check instead, which passed
for (i <- 1 to 3) println(refineMV[Positive](i))
Prints outs: 1 2 3
-
Compile time check could not run, so running runtime check instead, which failed and throws exception
for (i <- -1 to 3) println(refineMV[Positive](i)) //Throws exception
Note: Instead of modifying refineMV you may wish to keep it as is, and add another flavor (something like refineMVRE [Macro Verify, Runtime Exception], or whatever acronym you wish). However, I don’t think you should. Keep it simple with the least functions possible.
Thanks, Oron
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top GitHub Comments
@fthomas i’m trying to make this one https://github.com/fthomas/refined/compare/topic/unsafeFrom2 work
@ysusuk I created a solution using the singleton-ops library, which is called
TwoFace
andChecked
values. You can read about it in the following link: https://contributors.scala-lang.org/t/twoface-values-closing-the-gap-between-run-compile-time-functionality/869