Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unexpected behavior with proofs plugin. #949

Open
Sintrastes opened this issue Dec 5, 2021 · 0 comments
Open

[BUG] Unexpected behavior with proofs plugin. #949

Sintrastes opened this issue Dec 5, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@Sintrastes
Copy link

Describe the bug
When using the latest snapshot of the proofs plugin (2.0.0-SNAPSHOT) and using it to test out a generic numeric function with given instances for Int and Double I encountered some strange behavior, where when I expected the proofs plugin to use the Double instance, it seems to be using the Int instance, and coercing the passed Doubles to and from Int.

To Reproduce

Run the following example with the proofs plugin, version 2.0.0-SNAPSHOT:

package test
import arrow.Context

@Context
@Retention(AnnotationRetention.RUNTIME)
@Target(
  AnnotationTarget.CLASS,
  AnnotationTarget.FUNCTION,
  AnnotationTarget.PROPERTY,
  AnnotationTarget.VALUE_PARAMETER
)
@MustBeDocumented
annotation class Given
inline fun <A> given(@Given identity: A): A = identity

interface Num<A> {
    val zero: A
    operator fun A.plus(other: A): A
    operator fun A.times(other: A): A
}

@Given
internal val intNum = object: Num<Int> {
  override val zero: Int = 0

  override fun Int.plus(other: Int): Int {
    return this + other
  }

  override fun Int.times(other: Int): Int {
    return this * other
  }
}

@Given
internal val doubleNum = object: Num<Double> {
  override val zero = 0.0

  override fun Double.plus(other: Double): Double {
    return this + other
  }

  override fun Double.times(other: Double): Double {
    return this * other
  }
}

fun <A> someNumericFunction(
    x: A, y: A,
    @Given num: Num<A>
): A = with(num) {
    return x + y
}

val x = someNumericFunction(2,2)

val y = someNumericFunction(2.2,2.2)

fun main() {
  // Got: 4 4.0
  // Expected: 4 4.4
  println("$x $y")
}

Environment (please complete the following information):

  • Kotlin version [eg. 1.3.61]: 1.6.0
  • [Kotlin Intellij IDEA plugin version]: Not sure (I used the latest arrow MPP template)
  • Intellij IDEA version: 2021.3
@Sintrastes Sintrastes added the bug Something isn't working label Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant