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

Illegal class file dependency with annotations #7551

Closed
scabug opened this issue Jun 3, 2013 · 6 comments
Closed

Illegal class file dependency with annotations #7551

scabug opened this issue Jun 3, 2013 · 6 comments

Comments

@scabug
Copy link

scabug commented Jun 3, 2013

Create the following files:

// p/A.java
package p;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface A {
    Class<?> subInterface();
}
// p/T.scala
package p

@A(subInterface = classOf[T.S])
trait T {
}

object T {
  private[p] trait S extends T { }
}
// p/Foo.scala
package p

object Foo {
  def bar(t: T) { }
}

Now compile them, in order, one at a time.

javac p/A.java
scalac p/T.scala
scalac p/Foo.scala

The last command should give you an internal error.

error: error while loading T, illegal class file dependency between 'object T' and 'class T'
warning: Caught: java.lang.AssertionError: assertion failed:
     while compiling: p\Foo.scala
        during phase: global=typer, atPhase=namer
     library version: version 2.10.1
    compiler version: version 2.10.1
  reconstructed args:

  last tree to typer: Ident(T)
              symbol: <none> (flags: )
   symbol definition: <none>
       symbol owners:
      context owners: value t -> method bar -> object Foo -> package p

== Enclosing template or block ==

DefDef( // def bar: <?> in object Foo
  <method> <locked>
  "bar"
  []
  // 1 parameter list
  ValDef( // t: <?>
    <param> <locked>
    "t"
    "T"
    <empty>
  )
  "scala"."Unit" // final abstract class Unit extends AnyVal in package scala, tree.tpe=Unit
  ()
)

(p.T$S,p.T,S,class T in package p) /  while parsing (.\p\T.class,Some(class T))class T.S linkedModule: object TScope{

} while parsing annotations in .\p\T.class
one warning found
one error found
@scabug
Copy link
Author

scabug commented Jun 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7551?orig=1
Reporter: Роман Донченко (dpb)
Affected Versions: 2.10.1

@scabug
Copy link
Author

scabug commented Jun 4, 2013

@retronym said:
We should fault tolerant with these. Or maybe not parse them at all during class file reading.

WIP: https://github.com/retronym/scala/compare/ticket/7551

@scabug
Copy link
Author

scabug commented Nov 9, 2014

@soc said:
In Scala 2.11.4, this just reports a normal error:

error: error while loading T, illegal class file dependency between 'object T' and 'class T'
one error found

@scabug
Copy link
Author

scabug commented Oct 28, 2016

@lrytz said:
The example no longer crashes after scala/scala#5482, but it's not a fix, just a workaround (don't parse java classfile annotations on scala classfiles).

@scabug
Copy link
Author

scabug commented Dec 31, 2016

Christian Schlichtherle (christian_schlichtherle) said:
This issue has apparently been fixed in Scala 2.12.1, which is great! Is there any chance it will be back-ported to the Scala 2.11.x branch? This is a showstopper for projects which can't change third party Java annotations and cannot yet upgrade to Scala 2.12.x.

@SethTisue
Copy link
Member

closing since the crash is fixed. I haven't investigated whether there was any further progression in this area since 2.12.1, but if "parse java classfile annotations on scala classfiles" merits a separate ticket (and one doesn't already exist), y'all can feel free to open one

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

3 participants