Skip to content
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

Implicit search ignores implicit definitions for a subtype imported from inside a parameter value #12721

Open
yoohaemin opened this issue Jan 29, 2023 · 4 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Milestone

Comments

@yoohaemin
Copy link

Reproduction steps

Scala version:
2.13.10 (https://scastie.scala-lang.org/DXf5ct0bSCOWZkyrZtmDQQ)
2.12.17 (https://scastie.scala-lang.org/1ZQxsfQvRxeA1ulIZcTI6Q)

Note: 3.2.2 behaves as expected (https://scastie.scala-lang.org/o9DgmHrBQ0ymlC3KHnxfqg)

trait Module {
  trait X[A]
  object X {
    trait One[A] extends X[A]
  }

  implicit def ya: X.One[a]
}

class a

object Test {
  def ok(module: Module) = {
    val x = module
    import x._

    implicitly[X[a]]
  }

  def notOk(module: Module) = {
    import module._

    implicitly[X[a]] //fails
  }
}

Output

/path/to/source.scala:23:15: implicit error;
!I e: module.X[<empty>.a]
    implicitly[X[a]] //fails
              ^
one error found

Expected behavior

Code compiles

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Jan 29, 2023
@som-snytt
Copy link

The matchesPt test in ImplicitComputation uses depoly which is commented why it's handling the dependent type as it does. No idea if this is a fundamental restriction or can be tweaked.

Scala 3 shows:

def ok(module: Module): Module#X[a]
def notOk(module: Module): module.X[a]

@som-snytt
Copy link

som-snytt commented Feb 1, 2023

perhaps relatedly #5070

OH: "changing implicit resolution is too risky in a minor release"

@yoohaemin
Copy link
Author

yoohaemin commented Feb 2, 2023

I see. Thanks for setting the expectation. Still for me it would be great if it can be fixed, my library makes use of this pattern pretty often.

@som-snytt
Copy link

Apologies, that was an old quote in a linked ticket, and I intended to highlight the irony that there is never a good time to change implicit resolution. But Scala 3 permits us to backport behavior under -Xsource:3. Also, maybe this is just a fixable bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Projects
None yet
Development

No branches or pull requests

3 participants