Skip to content

want to refer Java Library but compile error. cyclic reference involving module class #4357

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
keiSunagawa opened this issue Apr 21, 2018 · 2 comments

Comments

@keiSunagawa
Copy link

I want to use Java Library from Dotty code.
but particular code is touch off compile error.

this is problem code.

// file myexample/A.java
package myexample;

public class A<T> {}

// file B.java
package myexample;

public class B extends A<B.C> {
  public static class C {};
}

They're compiled by Java8.

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

$ javac myexample/A.java
$ javac myexample/B.java

This is the code of Dotty referencing them.

import myexample.B

object Main extends App {
  val b: B = new B()
}

This become compile error. dotc0.7.0-RC1.

$ dotc -version
Dotty compiler version 0.7.0-RC1 -- Copyright 2002-2018, LAMP/EPFL

$ tree ./
./
├── C.scala
└── myexample
    ├── A.class
    ├── A.java
    ├── B$C.class
    ├── B.class
    └── B.java

$ dotc -explain -classpath ./ C.scala
exception caught when loading class C: java.lang.UnsupportedOperationException: class dotty.tools.dotc.core.SymDenotations$NoCompleter.complete
exception caught when loading class B: dotty.tools.dotc.core.Types$CyclicReference: cyclic reference involving module class B$
-- [E046] Syntax Error: C.scala:4:9 --------------------------------------------
4 |  val b: B = new B()
  |         ^
  |         cyclic reference involving object B

Explanation
===========
object B is declared as part of a cycle which makes it impossible for the
compiler to decide upon B$'s type.

-- [E006] Unbound Identifier Error: C.scala:4:17 -------------------------------
4 |  val b: B = new B()
  |                 ^
  |                 not found: type B

Explanation
===========
The identifier for `type B` is not bound, that is,
no declaration for this identifier can be found.
That can happen for instance if B or its declaration has either been
misspelt, or if you're forgetting an import

two errors found

Is there a way to successed compile without modify java code?
and then is this a bug?

@smarter
Copy link
Member

smarter commented Apr 21, 2018

Thank you for the minimal test case! Yes, this is a bug in the Java classfile parser, unfortunately there's no way to workaround this without changing the Java code.

@keiSunagawa
Copy link
Author

ok. I'm decided to patiently waiting for the bug fix.
Thanks.

smarter added a commit that referenced this issue Apr 22, 2018
Fix #4357: Avoid cyclic reference when parsing Java classfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants