Skip to content

Relaxed import also unshadows #22583

Open
@som-snytt

Description

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions