Skip to content
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

Spurious cyclic reference error with package objects and separate compilation #2551

Closed
xeno-by opened this issue May 28, 2017 · 5 comments · Fixed by #2555
Closed

Spurious cyclic reference error with package objects and separate compilation #2551

xeno-by opened this issue May 28, 2017 · 5 comments · Fixed by #2555

Comments

@xeno-by
Copy link
Member

xeno-by commented May 28, 2017

// Library.scala
package scala {
  package meta {
    package config {
      case class Version()

      trait Aliases {
        type Version = scala.meta.config.Version
        val Version = scala.meta.config.Version
      }
    }
  }

  package object meta extends scala.meta.config.Aliases
}
// Test.scala
import scala.meta._

object Test {
  val v = Version()
}
17:46 ~/Projects/dotty/sandbox $ ../bin/dotc Library.scala
17:46 ~/Projects/dotty/sandbox $ ../bin/dotc Test.scala
exception caught when loading class Aliases: dotty.tools.dotc.core.Types$CyclicReference: cyclic reference involving class Aliases
-- [E044] Syntax Error: Test.scala:4:10 ----------------------------------------
4 |  val v = Version()
  |          ^^^^^^^
  |          recursive value v needs type

longer explanation available when compiling with `-explain`

one error found

Notes:

  • When Library.scala is compiled with scalac, we get the same error (so it's not a ScalaSignature vs TASTY problem). upd: I was wrong - when Library.scala is compiled with scalac, compilation succeeds.
  • When both Library.scala and Test.scala are compiled with scalac, compilation succeeds.
  • When there's just one file that merges these two files together, compilation succeeds.
@xeno-by
Copy link
Member Author

xeno-by commented May 28, 2017

Unfortunately, this issue is quite a blocker for me, because it prevents Scalameta metaprograms from crosscompiling to Dotty. This pattern of organizing packages is quite pervasive to Scalameta, so I can't see an easy workaround at the moment.

I'm reasonably sure that this design pattern worked in earlier builds of Dotty around Sep 2016, because at that time we had meta-based macro annotations expand in scalac, dotc and intellij. Is there an easy way to go back in time to verify this?

I'd appreciate if someone could take a quick look at this issue, because I'm a bit overwhelmed with other preparations to Copenhagen. I may also be able to take a stab at fixing this myself if you guys could provide some pointers.

@liufengyun
Copy link
Contributor

If the library is compiled with scalac, everything works fine to me:

scalac examples/library.scala
dotc examples/test.scala

It is only a problem if both are compiled with dotc. I guess you only need to compile test.scala with dotc, thus avoid the problem.

@xeno-by
Copy link
Member Author

xeno-by commented May 28, 2017

@liufengyun Thank you for double-checking. Indeed, I was incorrect (that was called by a mixup in my scalac and dotc scripts). If Library.scala is compiled by scalac, Test.scala can then be correctly compiled by dotc.

This means that only Scalameta itself can't be crosscompiled by Dotty (well, it can, but then it will be unusable). Scalameta metaprograms can and indeed are successfully crosscompiled.

@liufengyun
Copy link
Contributor

@xeno-by If you are doing a fork of Dotty, you can try the solution in #2555 .

@xeno-by
Copy link
Member Author

xeno-by commented May 29, 2017

@liufengyun Thanks a lot! I'll keep this in mind.

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