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

crashers in annotation argument handling in scaladoc #7367

Closed
scabug opened this issue Apr 14, 2013 · 4 comments
Closed

crashers in annotation argument handling in scaladoc #7367

scabug opened this issue Apr 14, 2013 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Apr 14, 2013

Annotation handling in Scaladoc crashes in two related circumstances:

  1. An annotation is constructed with a non-primary constructor.
class annot() extends annotation.StaticAnnotation {
  def this(a: Any) = this()
}

@annot(0)
class B
	at scala.tools.nsc.doc.model.ModelFactory$$anon$19.<init>(ModelFactory.scala:908)
	at scala.tools.nsc.doc.model.ModelFactory.makeAnnotation(ModelFactory.scala:903)
	at scala.tools.nsc.doc.model.ModelFactory$EntityImpl$$anonfun$annotations$1.apply(ModelFactory.scala:100)
  1. When calling a Java annotation in the sources, Scaladoc generates documentation for that annotation, and crashes with an argument/parmaeter list length mismatch.
find src build.sbt -type f | xargs tail -n 1000
==> src/main/java/foo/A.java <==
package foo;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface A {
  int value();
}

==> src/main/scala/foo/B.scala <==
package foo

@A(123)
class B

This no longer causes a crash on 2.10.x since 50ee635e3c.

% RUNNER=scaladoc scala-hash '50ee635e3c' `find src -type f`
[info] 50ee635e3c => /Users/jason/usr/scala-v2.10.1-122-g50ee635
warning: dropping dependency on node with no phase object: pickler
model contains 4 documentable templates

% RUNNER=scaladoc scala-hash '50ee635e3c~1' `find src -type f`
[info] 50ee635e3c => /Users/jason/usr/scala-v2.10.1-121-gb7b4f87
warning: dropping dependency on node with no phase object: pickler
model contains 4 documentable templates
Exception in thread "main" java.lang.AssertionError: assertion failed: 

But it still seems like a bug that documentation is generated for Java sources.

@scabug
Copy link
Author

@scabug scabug commented Apr 14, 2013

@scabug
Copy link
Author

@scabug scabug commented Apr 14, 2013

@vigdorchik said:
IIRC scaladoc has always been capable of (and used for) java source code documentation, so there's no bug there.

@scabug
Copy link
Author

@scabug scabug commented Apr 14, 2013

@SethTisue said (edited on Apr 14, 2013 5:25:43 PM UTC):
re: Scaladoc processing Java sources, see #4826. (it's good that it handles them even to the limited extent that it does, and ideally it would handle them even better!)

SBT can be told to ignore Java sources in its scaladoc generation task; see http://stackoverflow.com/questions/8884866/sbt-doc-command-how-to-exclude-java-source-files

@scabug
Copy link
Author

@scabug scabug commented Apr 14, 2013

@retronym said (edited on Apr 14, 2013 6:40:38 PM UTC):
In the compiler universe, it seems you can use Annotation#original. I use a macro and liberal casting to show that here:

scala> def impl(c: Context) = {
  val g = c.universe.asInstanceOf[scala.tools.nsc.Global]
  val tp = c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.asInstanceOf[g.analyzer.Typer]
  println(tp.context.enclClass.owner.annotations.map(_.original.symbol.defString))
  c.literalUnit 
}
impl: (c: scala.reflect.macros.Context)c.Expr[Unit]

scala> def enclAnnotationsOriginals = macro implenclAnnotationsOriginals: Unit

scala> @annot(0) class B { enclAnnotationsOriginals }
List(def <init>(a: Any): annot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants