Skip to content

"missing argument" for default annotation parameter to Java interface #2760

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

Closed
olafurpg opened this issue Jun 15, 2017 · 4 comments
Closed

Comments

@olafurpg
Copy link
Contributor

$ cat <<EOT >> bench.scala
package foo

@Fork(value = 16)
class Bar
EOT
$ cat <<EOT >> fork.java
package foo;

public @interface Fork {
    int value() default -1;
    int warmups() default -1;
}
EOT
$ scalac bench.scala fork.java # using 2.12.2
$ dotc bench.scala fork.java
-- Error: bench.scala:3:0 ------------------------------------------------------
3 |@Fork(value = 16)
  |^^^^^^^^^^^^^^^^
  |missing argument for parameter warmups of constructor Fork: (value: Int, warmups: Int)foo.Fork

one error found
@odersky
Copy link
Contributor

odersky commented Jan 17, 2018

It's the Java parser that does not generate the default correctly. If we compile Fork.java separately, it works.

@odersky
Copy link
Contributor

odersky commented Jan 17, 2018

Here's what we get from the Java parser:

package foo {
  object Fork() extends {}
  abstract class Fork(val value: Int, val warmups: Int) extends _root_.scala.
    annotation
  .Annotation with _root_.java.lang.annotation.Annotation with _root_.scala.
    annotation
  .ClassfileAnnotation {}
}

The default arguments are missing. I believe that's no oversight. To do this, we'd need to be able to parse expressions (actually: only constant expressions), and that functionality is currently missing.

@smarter
Copy link
Member

smarter commented Jan 17, 2018

To do this, we'd need to be able to parse expressions (actually: only constant expressions), and that functionality is currently missing.

I don't think that's necessary, we already record whether annotations parameters have default values with a special annotation (https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala#L518) and that should be enough to compile uses of Java annotations. I think we just need to add dummy default getters for these parameters like we do when parsing from a classfile: https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala#L640-L645

@odersky
Copy link
Contributor

odersky commented Jan 18, 2018

We do record an AnnotationDefault attribute, but we don't record what that attribute is. To do so, we have to parse the default value, which is currently done using unimplementedExpr, returning a ???`.

I think this would be a great contribution for someone who tries to get into the compiler code base. It's tricky, but requires only a limited footprint of pre-existing knowledge about the compiler.

smarter added a commit to dotty-staging/dotty that referenced this issue Jan 18, 2018
smarter added a commit to dotty-staging/dotty that referenced this issue Jan 18, 2018
smarter added a commit to dotty-staging/dotty that referenced this issue Jan 18, 2018
smarter added a commit to dotty-staging/dotty that referenced this issue Feb 1, 2018
@smarter smarter self-assigned this Mar 23, 2018
odersky added a commit that referenced this issue Mar 26, 2018
Fix #2760: Support defaults in Java annotations parsed from sources
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