Skip to content

Import outside a package clause is not shadowed by an import inside the package clause #21405

Closed
@som-snytt

Description

@som-snytt

Compiler version

3.4.2

Minimized code

package p {
  class IO
}
import java.io.*
package q {
  import p.*
  class D extends IO
}

Output

-- [E049] Reference Error: masked.scala:8:18 ---------------------------------------------------------------------------
8 |  class D extends IO
  |                  ^^
  |                  Reference to IO is ambiguous.
  |                  It is both imported by import java.io._
  |                  and imported subsequently by import p._
  |
  | longer explanation available when compiling with `-explain`
1 error found

Expectation

p.IO shadows java.io.IO as in Scala 2.

This test requires JDK 23, but let me minimize properly, which also fails in the same way:

package r {
  class IO
}
package p {
  class IO
}
//import java.io.*
import r.*
package q {
  import p.*
  class D extends IO

  object Test extends App {
    println(new D().getClass.getSuperclass.getName)
  }
}

Note that -Yimports:java.io,p works correctly (without imports in source), as expected.

The issue is urgent where p is cats.effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions