Hey, i'm experimenting with Arrow Analysis, and I ...
# arrow
t
Hey, i'm experimenting with Arrow Analysis, and I noticed something. I think I kinda guess why this works like this, but thought it would be interesting to share: I was trying to see how far I can take Arrow Analysis and I was writing a Spring Boot application and tried to see what happened if I used this as a
PathVariable
Copy code
@RestController
class MyController {

    @JvmInline
    value class Positive(val value: Int) {
        init { require(value > 0) }

        operator fun plus(other : Positive) = Positive(this.value + other.value)
    }

    @GetMapping("/{id}")
    fun getTypeWithId(@PathVariable("id") id : Positive) : ResponseEntity<Positive>{
        println(id)
        return ResponseEntity.ok(id)
    }
}
Turns out, if I send a request with the value
-1
it will actually print and return
-1
, so I just managed to create a Positive negative value ๐Ÿ˜„ So it compiles, and it seems that jackson is ignoring the
require
when creating a value class. (I am aware that this is not Arrows fault, just wanted to share)
e
Configure spring to use kotlinx.serialization and it should work as expected :)
๐Ÿ‘Œ 2
s
Probably one for #jackson-kotlin or #spring. Inline classes don't play well with anything Java/reflection ๐Ÿ˜ž
t
now im encoutering https://github.com/arrow-kt/arrow-meta/issues/1021 ๐Ÿ˜› but thx anyway!
e
Oh, sorry ๐Ÿ™ˆ
t
Nah, this is good ๐Ÿ™‚ I learned a new thing again! thx for the quick resposes!
a
sorry for the late reply the current implementation would only check the invariant when using the constructor directly... if you use reflection (or whatever spring boot uses) then you can still get wrong results
๐Ÿ‘ 1