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

Relaxed import also unshadows #22583

Open
som-snytt opened this issue Feb 11, 2025 · 0 comments
Open

Relaxed import also unshadows #22583

som-snytt opened this issue Feb 11, 2025 · 0 comments

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.6.3

Minimized code

object X:
  extension (s: String) def huh = s.reverse

object Y:
  def f(): String =
    import X.huh
    val huh = "huh".huh
    huh

@main def test() = println:
  Y.f()

Output

huh

Expectation

DNC as with

val huh = huh("huh")

because the extension fails the visible under a simple name test.

The doc says

If m is imported by several imports which are all on the nesting level, try each import as an extension method instead of failing with an ambiguity.

That is, relaxed imports disambiguates among possible imports, not between an import and a local definition.

If the weird behavior is intended, then the doc should be more explicit about this use case.

Noticed at https://github.com/scala/scala3/blob/3.6.3/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala#L2709

where the diff looks unintended:

Image

Imports are not relaxed with respect to local extension methods:

object Z:
  import X.huh
  extension (i: Int) def huh = i.toString.reverse
  val huh = "huh".huh // Required: Int
  def f(): String = huh
@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 11, 2025
@Gedochao Gedochao added area:extension-methods area:spec and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 12, 2025
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