than_

    than_

    1 year ago
    Hi, when trying to define my own refined types I'm getting an
    java.lang.IllegalArgumentException: object is not an instance of declaring class : package.PositiveInt2.Companion.invoke
    This happens just by defining new refined type. I tried to copy
    PositiveInt
    and just change the name
    class PositiveInt2 private constructor(val value: Int) {
        companion object : Refined<Int, PositiveInt2>(::PositiveInt2, {
            ensure((it > 0) to "$it should be > 0")
        })
    }
    is it a bug in a
    io.arrow-kt:arrow-refined-types-gradle-plugin:1.5.0-SNAPSHOT
    or am I missing something?
    raulraja

    raulraja

    1 year ago
    Hi @than_ are you using any other compiler plugins in that project?
    than_

    than_

    1 year ago
    kotlinx.serialization
    some others as well. it happens in multiple projects
    plugins {
        kotlin("multiplatform") version "1.5.0"
        kotlin("plugin.serialization") version "1.5.0"
        kotlin("kapt") version "1.5.0"
        id("com.github.johnrengelman.shadow") version "6.1.0"
        id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
        application
    }
    and
    plugins {
        id("com.android.application")
        id("kotlin-android")
        id("kotlin-kapt")
        id("org.jetbrains.kotlin.plugin.serialization") version "1.5.0"
        id("kotlin-parcelize")
    }
    raulraja

    raulraja

    1 year ago
    I have not seen that error before. I suppose one of those other plugins is mangling the class somehow. I would try with a regular value class just in case:
    @JvmInline
    value class PositiveInt private constructor(val value: Int) {
      companion object : Refined<Int, PositiveInt>(::PositiveInt, {
        ensure((it > 0) to "$it should be > 0")
      })
    }
    If that doesn’t work please feel free to create an issue with a minimal repro project and we can take a look at it before the next snapshot release. This plugin is not stable yet.
    than_

    than_

    1 year ago
    Thanks for your time. I understand all things meta related are not stable yet.
    For anyone interested: Bug report here https://github.com/arrow-kt/arrow-meta/issues/825
    raulraja

    raulraja

    1 year ago
    thanks @than_ 🙂