Feature request: Add runtime exception check instead of error "compile-time refinement only works with literals"
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 152
- Avg merge
- 1h 20m
- Merged PRs (30d)
- 6
Description
Hi,
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:
1. **Compile time check pass for literal (no runtime check required)**
```
println(refineMV[Positive](1))
```
Prints outs:
1
2. **Compile time check fail for literal**
```
println(refineMV[Positive](0))
```
3. **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
4. **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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the refineMV entry point named in the issue and compare its current literal-only behavior with the four examples. Done means literal checks retain compile-time behavior, non-literals use runtime validation, and failures throw an exception; no file or test path is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100