Skip to content

Export+import cause Cyclic reference involving val <import> error #13120

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
soronpo opened this issue Jul 20, 2021 · 4 comments · Fixed by #13720
Closed

Export+import cause Cyclic reference involving val <import> error #13120

soronpo opened this issue Jul 20, 2021 · 4 comments · Fixed by #13720
Assignees

Comments

@soronpo
Copy link
Contributor

soronpo commented Jul 20, 2021

This error was very difficult to minimize.
Features that are participating: opaque types, export, and import.
In the example, if the opaque directly refers to container.ir.Foo there is no error.
If we remove the export, there is no error.

Compiler version

3.0.3-RC1-bin-20210716-cc47c56-NIGHTLY

Minimized code

Minimized project at: https://github.com/soronpo/dottybug/tree/export_cyclic_err

container.scala

object container:
  object ir:
    sealed trait Foo

Foo.scala

import container.ir

opaque type Foo = ir.Foo

object Foo:
  def bar(foo: Foo): Unit = {}

export Foo.*

Output

[error] -- [E046] Cyclic Error: C:\IdeaProjects\dottybug\src\main\scala\Foo.scala:3:18 ----------------------------
[error] 3 |opaque type Foo = ir.Foo
[error]   |                  ^
[error]   |                  Cyclic reference involving val <import>
[error] one error found

Expectation

No error.

@soronpo
Copy link
Contributor Author

soronpo commented Jul 20, 2021

I made another check, and it turns out opaque has no play here. If we change Foo.scala the following, we still get the same error.

import container.ir

trait Foo extends ir.Foo

object Foo:
  def bar(foo: Foo): Unit = {}

export Foo.*

@soronpo soronpo changed the title Export+opaque+import cause Cyclic reference involving val <import> error Export+import cause Cyclic reference involving val <import> error Jul 20, 2021
@griggt
Copy link
Contributor

griggt commented Jul 20, 2021

For the original example where Foo is opaque, joint compilation is successful, but separate compilation produces the cyclic reference error.

For the revised example without the opaque type, joint compilation fails with:

$ dotc container.scala Foo.scala 
-- [E112] Syntax Error: Foo.scala:3:6 --------------------------------------------------------------
3 |trait Foo extends ir.Foo
  |      ^
  |      Cannot extend sealed trait Foo in a different source file

whereas separate compilation reports the same cyclic reference error as before.

@soronpo
Copy link
Contributor Author

soronpo commented Jul 21, 2021

For the original example where Foo is opaque, joint compilation is successful, but separate compilation produces the cyclic reference error.

For the revised example without the opaque type, joint compilation fails with:

$ dotc container.scala Foo.scala 
-- [E112] Syntax Error: Foo.scala:3:6 --------------------------------------------------------------
3 |trait Foo extends ir.Foo
  |      ^
  |      Cannot extend sealed trait Foo in a different source file

whereas separate compilation reports the same cyclic reference error as before.

Change the sealed trait Foo into a trait, and you will get the same response I believe.

@Kordyjan
Copy link
Contributor

Change the sealed trait Foo into a trait, and you will get the same response I believe.

Confirmed. The joint compilation is successful, but compiling Foo.scala separately fails with Cyclic reference error.

@bishabosha bishabosha self-assigned this Jul 21, 2021
soronpo added a commit to soronpo/scala3 that referenced this issue Oct 8, 2021
smarter added a commit that referenced this issue Oct 8, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
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.

4 participants