lightbend / genjavadoc

A compiler plugin for generating doc’able Java source from Scala source

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid javadoc generated when using Scala 2.13.4

marcospereira opened this issue · comments

Project to reproduce the problem: https://github.com/marcospereira/scala-2.13.4-genjavadoc-failure

Java version:

openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)

The code generated when using Scala 2.13.4 is:

// cat target/java/com/acme/Foo.java
package com.acme;
/**
 * @return something something
 */
// not preceding
public  class Foo {
  // not preceding
  static public  java.lang.String bar ()  { throw new RuntimeException(); }
}

// cat target/java/com/acme/Foo$.java
package com.acme;
/**
 * @return something something
 */
// not preceding
public  class Foo$ {
  /**
   * Static reference to the singleton instance of this Scala object.
   */
  public static final Foo$ MODULE$ = null;
  public   Foo$ ()  { throw new RuntimeException(); }
  // not preceding
  public  java.lang.String bar ()  { throw new RuntimeException(); }
}

And then Javadoc fails with:

[error] /tmp/scala-2.13.4-genjavadoc-failure/target/java/com/acme/Foo$.java:3:1: invalid use of @return
[error] /tmp/scala-2.13.4-genjavadoc-failure/target/java/com/acme/Foo.java:3:1: invalid use of @return

The (valid) code generated when using Scala 2.13.3 is:

// cat target/java/com/acme/Foo.java
package com.acme;
/**
 * A simple class
 */
public  class Foo {
  /**
   * @return something something
   */
  static public  java.lang.String bar ()  { throw new RuntimeException(); }
}

// cat target/java/com/acme/Foo$.java
package com.acme;
/**
 * A simple class
 */
public  class Foo$ {
  /**
   * Static reference to the singleton instance of this Scala object.
   */
  public static final Foo$ MODULE$ = null;
  public   Foo$ ()  { throw new RuntimeException(); }
  /**
   * @return something something
   */
  public  java.lang.String bar ()  { throw new RuntimeException(); }
}

The same happens with Scala 2.13.5.

This is caused by -Yrangepos being enabled by default in 2.13.4+.

Adding -Yrangepos:false makes it work on 2.13.4/5, adding -Yrangepos:true causes the same failure on 2.13.3.

The test suite runs without range positions by default

/** whether to enable -Yrangepos */
def rangepos: Boolean = false

@raboof noticed this before at #220

Oh, good. I'm gonna close this one then as a duplicate. Thanks, @lrytz!