Skip to content

Unexpected ambiguous argument in inline given instance #14194

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

Closed
Iltotore opened this issue Dec 31, 2021 · 1 comment
Closed

Unexpected ambiguous argument in inline given instance #14194

Iltotore opened this issue Dec 31, 2021 · 1 comment

Comments

@Iltotore
Copy link
Contributor

Iltotore commented Dec 31, 2021

Compiler version

3.1.0

Minimized code

class Test[A, B]

inline given [A, B](using A): Test[A, Test[A, B]] = new Test

given Int = 0
given String = ""

summon[Test[Int, Test[Int, String]]] //Working

Output

The above example works but if I try to summon[Test[Int, Test[String, Int]]], this produces an ambiguous implicit argument at using A.

I did some tests and noticed these behaviours:

  • Works when removing the inline modifiers (skipped because Test[Int, Test[String, Int]] doesn't match Test[A, Test[A, B]])
  • Works if there's no using A (skipped because Test[Int, Test[String, Int]] doesn't match Test[A, Test[A, B]])
  • Works if A and B are covariant in Test
  • Doesn't work if A and B are invariant or contravariant

From what I tested, the compiler seems to try to get the using A parameter where A = ? before checking the returned type.

Expectation

I would expect the compiler to just ignore inline given [A, B](using A): Test[A, Test[A, B]] = new Test when summoning Test[Int, Test[String, Int]] and search for another given instance (or raise a "no implicit found" error if there's no matching instance).

I actually see 2 potential solutions:

  • Make the compiler verify the returned type when he tries to infer the generic types before looking for the using parameter(s)
  • If a given instance produces an ambiguity error, check for another matching given instance before raising it.

Note: this is possibly related to #7586 and #14169

@Iltotore
Copy link
Contributor Author

This issue seems to be fixed in 3.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants