question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Add runtime exception check instead of error "compile-time refinement only works with literals"

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ysusukcommented, Jul 3, 2017
1reaction
soronpocommented, Jun 30, 2017

@ysusuk I created a solution using the singleton-ops library, which is called TwoFace and Checked 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scala refined integer for both compile-time literal and run-time ...
Yes, but how to avoid the compile time error "compile-time refinement only works with literals"? If it's a literal I want the compiler...
Read more >
Wtf is Refined - Medium
It will only work with literal values which are values known at compile time. Because positiveInt value (first line) is known at compile...
Read more >
How to Handle Checked & Unchecked Exceptions in Java
An unchecked exception (also known as an runtime exception) in Java is something that has gone wrong with the program and is unrecoverable....
Read more >
Programming Languages which Implement Compile-Time ...
Can this sort of thing be checked at compile time in some cases, or must it all be done at runtime? That is,...
Read more >
Custom pluggable types for Java - The Checker Framework Manual
The .jar files are only compatible with a Java 8 JVM. Developers perform pluggable type-checking in-house to detect errors and verify their absence....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found