Scala Programming Language
  1. Scala Programming Language
  2. SI-7367

crashers in annotation argument handling in scaladoc

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.2-RC1
    • Component/s: None
    • Labels:

      Description

      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)
      

      2. 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.

        Activity

        Hide
        Eugene Vigdorchik added a comment -

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

        Show
        Eugene Vigdorchik added a comment - IIRC scaladoc has always been capable of (and used for) java source code documentation, so there's no bug there.
        Hide
        Seth Tisue added a comment - - edited

        re: Scaladoc processing Java sources, see SI-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

        Show
        Seth Tisue added a comment - - edited re: Scaladoc processing Java sources, see SI-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
        Hide
        Jason Zaugg added a comment - - edited

        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)
        
        Show
        Jason Zaugg added a comment - - edited 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)

          People

          • Assignee:
            Eugene Vigdorchik
            Reporter:
            Jason Zaugg
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development