Skip to content

Error "Cyclic reference involving module" when using export on top level #11141

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
bjornregnell opened this issue Jan 17, 2021 · 1 comment · Fixed by #11147
Closed

Error "Cyclic reference involving module" when using export on top level #11141

bjornregnell opened this issue Jan 17, 2021 · 1 comment · Fixed by #11147
Assignees
Milestone

Comments

@bjornregnell
Copy link
Contributor

bjornregnell commented Jan 17, 2021

Minimized code

In file test.scala:

package p
export X._

object X:
  val A = 42

Output

[info] compiling 1 Scala source to /home/bjornr/tmp/bug-repl/target/scala-3.0.0-M3/classes ...
[error] -- [E046] Cyclic Error: /home/bjornr/tmp/bug-repl/src/main/scala/p/test.scala:2:7 
[error] 2 |export X.A
[error]   |       ^
[error]   |       Cyclic reference involving module X
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

Export on top level should work.

There is a work-around: put the export in another file test2.scala and now both test.scala and test2.scala compiles:

package p

export X._

object Y {
  val B = A
}

Note that A is now visible on top level without an import X._ in file test2.scala , as expected.

Output with both files (but it shouldn't be necessary to put the export in another file...):

sbt:bug-repl> clean
[success] Total time: 0 s, completed Jan 17, 2021, 8:29:56 PM
sbt:bug-repl> console
[info] compiling 2 Scala sources to /home/bjornr/tmp/bug-repl/target/scala-3.0.0-M3/classes ...

scala> p.A                                                                      
val res0: Int = 42
@bjornregnell bjornregnell changed the title Error "Cyclic reference involving module" when using exporti on top level Error "Cyclic reference involving module" when using export on top level Jan 17, 2021
@bjornregnell
Copy link
Contributor Author

bjornregnell commented Jan 17, 2021

I have some problems with reproducing the work-around. Sometimes it works and sometimes not. It works more often after sbt clean but not always.

@bishabosha bishabosha self-assigned this Jan 18, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 18, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants