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

Default implicit not enabled for outer object if it is not a singleton #12952

Closed
tribbloid opened this issue Feb 16, 2024 · 12 comments
Closed

Default implicit not enabled for outer object if it is not a singleton #12952

tribbloid opened this issue Feb 16, 2024 · 12 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

Comments

@tribbloid
Copy link

tribbloid commented Feb 16, 2024

Reproduction steps

Scala version: 2.13.12

object ImplicitDefaultScope {
  trait Case[T]
  object case1 {
    trait Outer {
      case class A(v: String)
      implicit def caseA: Case[A] = ???
    }
    {
      def fn(o: Outer) = {
        implicitly[Case[o.A]]
      }
    }
  }
}

Problem

Compiles in Scala 3 (tested 3.4-SNAPSHOT)

Failed in Scala 2:

: could not find implicit value for parameter e: ai.acyclic.prover.commons.util.ImplicitDefaultScope.Case[o.A]
@tribbloid
Copy link
Author

wondering if there is an easy fix in Scala 2

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 16, 2024
@SethTisue
Copy link
Member

SethTisue commented Feb 16, 2024

When opening a ticket in scala/bug, please don't just offer code that doesn't compile; you are expected to make a case that this is a bug in Scala 2. Make arguments; link to related tickets; provide evidence that your minimization is actually minimal; consider quoting relevant spec language.

If you feel you don't have the time or energy for that and just want to ask your question, please use https://users.scala-lang.org instead of the bug tracker.

@SethTisue
Copy link
Member

btw, we've recently improved the repo readme here in scala/bug to emphasize this more; see #12950 and the recent discussion on #12949

@som-snytt
Copy link

som-snytt commented Feb 16, 2024

☑️ compiles in dotty

The implicit is available via the prefix of o.A, not just the prefix of Case. The implicit scope is the implicit scopes of all the parts.

(Note: these are not local types, which is a traditional heel of Achilles.)

@SethTisue
Copy link
Member

SethTisue commented Feb 16, 2024

Minimized a bit to remove distracting extra code:

trait Case[T]
trait Outer {
  case class A(v: String)
  implicit def caseA: Case[A] = ???
}
def fn(o: Outer) =
  implicitly[Case[o.A]]

@SethTisue
Copy link
Member

SethTisue commented Feb 16, 2024

As an example of what I mean by citing relevant documentation before filing a bug report, is there anything relevant in https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html ...? If you looked carefully and you became convinced that there isn't, say so in your report.

@som-snytt
Copy link

som-snytt commented Feb 16, 2024

☑️ tldr;

The important change is that packages in the prefix no longer contribute; that was lrytz's recent warning.

wondering if there is an easy fix in Scala 2

Not sure if "fix" means "workaround" or "fix that might make it into 2.13.14".

@SethTisue
Copy link
Member

that was lrytz's recent warning

I guess you mean scala/scala#10621 ? I haven't looked closely at it, but the title implies it's specific to package prefixes, but here the prefix o isn't a package?

@som-snytt
Copy link

Yes, I intended to say that the significant change does not apply to this case.

@tribbloid tribbloid changed the title Default implicit not enabled for outer object Default implicit not enabled for outer object if it is not a singleton Feb 17, 2024
@tribbloid
Copy link
Author

@SethTisue you are right they are different. The prefix o is a non-singleton, non-package object.

For the others, I'll try to revise all the tickets in the past (and re-open them if necessary)

@SethTisue
Copy link
Member

thanks. and yes, any closing of tickets is only provisional

@joroKr21
Copy link
Member

I think the relevant difference in the spec is:

Scala 3

If T is a reference to an anchor of the form p.A then S also includes all term references on the path p.

Scala2

if T is a singleton type p.type, the parts of the type of p;

"Parts of the type of p" include e.g. object Outer (because o: Outer) but not o.type itself.

@SethTisue SethTisue closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2024
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/)
Projects
None yet
Development

No branches or pull requests

4 participants