Skip to content

Wrong type inference within implicit resolution #18578

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
KuceraMartin opened this issue Sep 21, 2023 · 4 comments
Closed

Wrong type inference within implicit resolution #18578

KuceraMartin opened this issue Sep 21, 2023 · 4 comments
Labels

Comments

@KuceraMartin
Copy link
Contributor

Compiler version

3.3.1

Minimized code

trait Animal
class Dog extends Animal

trait Ev[T]
given Ev[Dog] = ???
given Ev[Animal] = ???
given [T: Ev]: Ev[Set[T]] = ???

def f[T: Ev](v: T): Unit = ???

def main =
  val s = Set(new Dog)
  f(s)
  f(Set(new Dog))

Output

[error] Ambiguous given instances: both given instance given_Ev_Dog and given instance given_Ev_Animal match type Ev[T] of an implicit parameter of method f
[error]   f(Set(new Dog))
[error]                  ^

Note that the error is from the very last line. The first call f(s) is okay.

From typer:

package <empty> {
  trait Animal() extends Object {}
  class Dog() extends Object(), Animal {}
  trait Ev[T >: Nothing <: Any]() extends Object {
    T
  }
  final lazy module val implicit-variance$package: implicit-variance$package =
    new implicit-variance$package()
  final module class implicit-variance$package() extends Object() {
    this: implicit-variance$package.type =>
    final lazy given val given_Ev_Dog: Ev[Dog] = ???
    final lazy given val given_Ev_Animal: Ev[Animal] = ???
    final given def given_Ev_Set[T >: Nothing <: Any](implicit evidence$1: Ev[T]
      ): Ev[Set[T]] = ???
    def f[T >: Nothing <: Any](v: T)(implicit evidence$2: Ev[T]): Unit = ???
    def main:

        <error both given instance given_Ev_Dog and given instance given_Ev_Animal match type Ev[T]>

     =
      {
        val s: Set[Dog] = Set.apply[Dog]([new Dog() : Dog]*)
        f[Set[Dog]](s)(given_Ev_Set[Dog](given_Ev_Dog))
        f[Set[Dog]](Set.apply[Dog]([new Dog() : Dog]*))(
          given_Ev_Set[T](
            /* ambiguous: both given instance given_Ev_Dog and given instance given_Ev_Animal match type Ev[T] */
              summon[Ev[T]]
          )
        )
      }
  }
}

Expectation

It should compile.

@KuceraMartin KuceraMartin added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 21, 2023
@Kordyjan Kordyjan added area:typer area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 22, 2023
@mbovel mbovel added the Spree Suitable for a future Spree label Nov 11, 2023
@scala-center-bot
Copy link

This issue was picked for the Issue Spree No. 39 of November 14th, 2023 which takes place in 7 days. @Linyxus, @jan-pieter, @eugenefle will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@hamzaremmal
Copy link
Member

hamzaremmal commented Nov 27, 2023

@Linyxus @EugeneFlesselle Can you add a comment about why this issue will not be fixed (You conclusion from the Spree). Thanks !

@EugeneFlesselle
Copy link
Contributor

@Linyxus @EugeneFlesselle Can you add a comment about why this issue will not be fixed (You conclusion from the Spree). Thanks !

I'm actually now working on another potential experimental fix #19096

@mbovel mbovel removed Spree Suitable for a future Spree stat:wontfix labels Jan 14, 2024
@EugeneFlesselle
Copy link
Contributor

Fixed by #19096

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

No branches or pull requests

8 participants