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
scalac reports error on valid Java class: illegal cyclic reference involving type T #4744
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4744?orig=1 |
@paulp said: |
@paulp said: |
Bhashit Parikh (bhashit) said (edited on May 31, 2014 3:19:46 PM UTC): This is the scenario:
If I compile just the java files, it works. If the scala code doesn't refer to that java class, it works.
|
Dmytro Kondratiuk (dk14) said: |
Arif (apathan) said: |
Per Mildner (per.mildner-at-sics.se) said: |
Per Mildner (per.mildner-at-sics.se) said: |
Per Mildner (per.mildner-at-sics.se) said: |
@SethTisue said: |
This comment was marked as outdated.
This comment was marked as outdated.
"Dotty is so right, it reports it twice!"
|
Hi @SethTisue, any updates on this? |
@eleansa no. nobody is working on this at present. a pull request with a fix would be very welcome |
Blows up in Typer. There's a "is this defined in Java" predicate in the model, so probably a good application of that where this is checked would suppress the error. The difficulty is figuring out how to not suppress it when it's right... |
Same issue has surfaced in Scala 3.1.2. I did not have this problem with 2.13. |
Scala 2 has an experimental option The program above proceeds to compile as far as:
Using The code that checks for this is: def findCyclicalLowerBound(tp: Type): Symbol = {
tp match {
case TypeBounds(lo, _) =>
// check that lower bound is not an F-bound
// but carefully: class Foo[T <: Bar[_ >: T]] should be allowed
for (tp1 @ TypeRef(_, sym, _) <- lo) {
if (settings.breakCycles) {
if (!sym.maybeInitialize) {
log(s"Cycle inspecting $lo for possible f-bounds: ${sym.fullLocationString}")
return sym
}
}
else sym.initialize
}
case _ =>
}
NoSymbol
} The caller to this method knows if we are checking a Java-defined symbol; it could pass this information in we could change the condition to: if (isJava || settings.breakCycles)` I'm not 100% sure, but I feel like the better approach might be to use a custom type traverser (rather than tp.foreach) that stops descending at the |
When compiling a mix of Java and Scala files, scalac will report an error on otherwise valid Java files.
To reproduce, create 2 files:
Foo.java:
Bar.scala:
And compile them using scalac:
Impact: it's not possible to use scala for mixed Scala/Java projects containing such declarations.
The text was updated successfully, but these errors were encountered: