-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
unexplained "ambiguous implicit arguments" error #14585
Comments
The actual context I'm seeing this error is here: |
@erikerlandson here's a potential workaround. 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 sameSame[VL, VR](using num: scala.math.Numeric[VL], same: VR =:= VL): Add[VL, VR] =
new Add[VL, VR]:
type VO = VL
def apply(vl: VL, vr: VR): VL = num.plus(vl, same(vr))
// trying to invoke this rule (differing types) causes strange error
transparent inline given different[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) |
@armanbilge that seems to work! |
I'm am going to leave this open because it still seems like a bug, feel free to close it otherwise |
Why does it look like a bug to you? Is there one of the two alternatives that is more specific than the other? if yes, why? |
My interpretation is that the first rule is "clearly" more specific, it has only one type parameter. Also, in any situation where the second rule matches (V1 not equal V2), the first should unambiguously fail, since it requires identical V in both type positions. I'm also puzzled by the particular nature of the error:
It should be looking for |
It does try the first rule, which is more specific. But it can't rule out the rule because of the presence of implicit conversions. There could be a type The whole thing should work if we get rid of implicit conversions. So that's a good demonstration what we could gain by such a step. |
I see, my mental model of how these searches behave doesn't include "account for possible implicit conversions" In general, I like the scala 3 concept of "you only get the implicit conversions that you deliberately import". If you (reasonably) do not wish to allow them, then do not import them. My drafts of scala-3-coulomb support this principle. Ignoring implicit conversions during context searching certainly seems like it would be cleaner. You get whatever matches without implicit conversion. I don't know if it is reasonable to decouple that from considering implicit conversions elsewhere, though. |
maybe what I'm suggesting is equivalent to: "implicit conversions should not apply to |
@erikerlandson Unfortunately, there's a lot of code that would not work anymore with that. |
thanks for looking at it! Being able to use |
@armanbilge I sure am grateful we have you in the Scala community. That's a handy trick to know 🙏 For anyone else following along from home, this is the |
Compiler version
3.1.1
Minimized code
The setup definitions
Output
Expectation
I would expect these rules to resolve correctly with no ambiguities
The text was updated successfully, but these errors were encountered: