You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data class PositiveIntEven private constructor(val value: Int) {
companion object : Refined<Int, PositiveIntEven>(::PositiveIntEven, PositiveInt, Even)
}
fun main() {
val n = -1
val result = PositiveInt(n).value
}
It is still compiled and throw an exception in runtime.
Output:
Exception in thread "main" java.lang.IllegalArgumentException: -1 should be > 0
at io.arrowkt.example.ContextKt.main(Context.kt:22)
at io.arrowkt.example.ContextKt.main(Context.kt)
Expected behavior
The code above should cause a compiler error:
error: Prefer a safe alternative such as PositiveInt.orNull(n) or for explicit use of exceptions `PositiveInt.require(n)`
The text was updated successfully, but these errors were encountered:
I think refined-type-plugin is properly published and it's being applied. It seems the issue comes from the plugin.
Including some cases here.
Example 1
Case 1.1 - Expected result
Input
val result = PositiveInt(-1).value
Compilation output
-1 should be > 0 : arrow.refinement.numbers.PositiveInt.Companion.invoke
It's the expected output. The plugin is being applied.
Case 1.2 - Expected result
Input
fun main() {
val result = PositiveInt(-1).value
}
Compilation output
-1 should be > 0 : arrow.refinement.numbers.PositiveInt.Companion.invoke
It's the expected output. The plugin is being applied.
Example 2
Case 2.1 - Expected result
Input
val n = -1
val result = PositiveInt(n).value
Compilation output
val n = -1 can't be verified at compile time. Use `Predicate.orNull(val n = -1)` for safe
access or `Predicate.require(val n = -1)` for explicit unsafe instantiation
It's the expected output according to this test of the plugin. The plugin is being applied.
Case 2.2 - NOT expected result
Input
fun main() {
val n = -1
val result = PositiveInt(n).value
}
main or any other function.
Compilation output
BUILD SUCCESSFUL
It's not the expected output. The plugin doesn't show the same behavior as before.
Describe the bug
refined-type-plugin is not getting applied when evaluating dynamic variables at compile time
To Reproduce
Update demo code with
It is still compiled and throw an exception in runtime.
Output:
Expected behavior
The code above should cause a compiler error:
The text was updated successfully, but these errors were encountered: