Skip to content

given failing to resolve when parameter is curried prior to using #19523

Closed as not planned
@erikerlandson

Description

@erikerlandson

Compiler version

scala 3.3.1

Minimized code

object reprodefs:
    trait Addable[V]:
        def add(x: V, y: V): V

    case class R[V](value: V):
        // this works
        def add(using alg: Addable[V])(r: R[V]): R[V] =
            R(alg.add(this.value, r.value))

        // putting 'r' before 'using alg' will fail
        def addFails(r: R[V])(using alg: Addable[V]): R[V] =
            R(alg.add(this.value, r.value))

    given scala.Conversion[R[Int], R[Double]] with
        def apply(r: R[Int]): R[Double] = R(r.value.toDouble)

    given Addable[Double] with
        def add(x: Double, y: Double): Double = x + y

object repro:
    import reprodefs.{*, given}
    import scala.language.implicitConversions

    // works fine
    val w = R(1.0).add(R(1))

    // this will cause compiler error where it incorrectly types
    // Addable and fails to find it
    val f = R(1.0).addFails(R(1))

Output

It seems to be incorrectly assigning type Addable[Double | Int] and so not finding it.

[error] 706 |    val f = R(1.0).addFails(R(1))
[error]     |                                 ^
[error]     |No given instance of type reprodefs.Addable[Double | Int] was found for parameter alg of method addFails in class R
[error] one error found
[error] (coreJVM / Compile / compileIncremental) Compilation failed

Expectation

I would expect the compiler to properly type Addable[] regardless of whether r was curried before or after the using alg parameter.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions