Closed
Description
Compiler version
3.1.1
Minimized code
The setup definitions
object repro:
abstract class Add[VL, VR]:
type VO
def apply(vl: VL, vr: VR): VO
object Add:
// invoking this rule(same-type args) seems to work as expected
transparent inline given [V](using num: scala.math.Numeric[V]): Add[V, V] =
new Add[V, V]:
type VO = V
def apply(vl: V, vr: V): V = num.plus(vl, vr)
// trying to invoke this rule (differing types) causes strange error
transparent inline given [VL, VR](using
nev: scala.util.NotGiven[VL =:= VR],
numL: scala.math.Numeric[VL],
numR: scala.math.Numeric[VR]): Add[VL, VR] =
new Add[VL, VR]:
type VO = Double
def apply(vl: VL, vr: VR): Double = numL.toDouble(vl) + numR.toDouble(vr)
transparent inline def plus[VL, VR](vl: VL, vr: VR)(using add: Add[VL, VR]): add.VO =
add(vl, vr)
Output
scala> import repro.*
scala> plus(1,1) // invoking with identical types works
val res0: Int = 2
scala> plus(1f,1f)
val res1: Float = 2.0
scala> plus(1d,1d)
val res2: Double = 2.0
scala> plus(1,1d) // attempting to trigger the different-types rule errors out unxpectedly
-- Error: ----------------------------------------------------------------------
1 |plus(1,1d)
| ^
|ambiguous implicit arguments of type coulomb.repro.Add[Int, Double] found for parameter add of method plus in object repro.
|I found:
|
| coulomb.repro.Add.given_Add_V_V[V](
| /* ambiguous: both object DoubleIsFractional in object Numeric and object LongIsIntegral in object Numeric match type Numeric[V] */
| summon[Numeric[V]]
| )
|
|But both object DoubleIsFractional in object Numeric and object LongIsIntegral in object Numeric match type Numeric[V].
1 error found
Expectation
I would expect these rules to resolve correctly with no ambiguities