Skip to content

Confusing error message with missing implicit doesn't show bounds of constrained type variables #12232

Closed
@dlwh

Description

@dlwh

Forgive is this is a dupe or a known change. I read the spec more carefully this time and watched @smarter's talk but didn't see anything that was directly addressing this. I think that Scala 3 is more aggressive at pinning primitive types than it used to be

Compiler version

3.0.0-RC2

Minimized code

trait Op[T1, T2, +R] {
  def apply(t1: T1, t2: T2): R
}

object Op {
  implicit val compInt: Op[Int, Int, Int] = new Op[Int, Int, Int] {
    def apply(x: Int, y: Int) = scala.math.min(x, y)
  }
}

object Foo {
  def foo(x: Double) = x + 1.0
  def min[T, U, V](x: T, y: U)(implicit op: Op[T, U, V]): V = op(x, y)
  def minInt(x: Int, y: Int)(implicit op: Op[Int, Int, Int]): Int = op(x, y)
  def minR[R](x: Int, y: Int)(implicit op: Op[Int, Int, R]): R = op(x, y)
  min(3, 4) // works in both
  foo(min(3, 4)) // works in Scala 2, not in 3
  foo(minInt(3, 4)) // works in both
  foo(minR(3, 4)) // works in Scala 2, not in 3
}

Output

17 |  foo(min(3, 4))
   |               ^
   |no implicit argument of type Op[Int, Int, V] was found for parameter op of method min in object Foo
19 |  foo(minR(3, 4))
   |                ^
   |no implicit argument of type Op[Int, Int, R] was found for parameter op of method minR in object Foo

Expectation

I'd prefer the Scala 2 behavior very much, though I can probably work around it with enough implicit magic, but at the very least, I'd prefer that the error message was a bit more specific: telling the user that V == Double or something. I was confused for a long time if there was some other change to implicit scope I didn't understand (the Op impls were elsewhere in my actual code)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions