Skip to content

Import fails to bind package name in preference to class definition in package #12166

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

Closed
som-snytt opened this issue Sep 27, 2020 · 1 comment

Comments

@som-snytt
Copy link

som-snytt commented Sep 27, 2020

reproduction steps

using Scala 2.13.3,

++ ./a/internal/C.scala

package a.internal

class C
++ ./b/Test.scala

package b

import a._

class Probe extends internal

object Test extends App {
  println(new Probe)
}
++ ./b/internal.scala

package b

class internal

problem

scalac prefers the wrong binding for internal and compilation succeeds.

dotc:

-- [E093] Syntax Error: ./b/Test.scala:6:6 -------------------------------------
6 |class Probe extends internal
  |      ^
  |      class Probe cannot extend final package a.internal

longer explanation available when compiling with `-explain`
-- Error: ./b/Test.scala:6:20 --------------------------------------------------
6 |class Probe extends internal
  |                    ^^^^^^^^
  |                    a.internal does not have a constructor
2 errors found

If instead

package b
object internal

then

./b/Test.scala:9: error: package a.internal is not a value
  println(internal)
          ^
1 error

Reported at scala/scala3#9899

@dwijnand dwijnand added should not compile fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) labels Oct 8, 2020
@dwijnand dwijnand added this to the Backlog milestone Oct 8, 2020
@som-snytt som-snytt removed fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) should not compile labels Feb 4, 2021
@som-snytt
Copy link
Author

This is not a bug. Packages dwell in the term namespace.

https://scala-lang.org/files/archive/spec/2.13/09-top-level-definitions.html#packagings

The spec makes this clear: "unlike other objects, they can't be used as values, only in selections. Other terms/types can't have the same fully qualified name." [paraphrased. -Ed.]

@SethTisue SethTisue removed this from the Backlog milestone Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants