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

Allow runtime values for argument and main annotations #14

Open
lihaoyi opened this issue Dec 4, 2021 · 0 comments
Open

Allow runtime values for argument and main annotations #14

lihaoyi opened this issue Dec 4, 2021 · 0 comments

Comments

@lihaoyi
Copy link
Member

lihaoyi commented Dec 4, 2021

Currently this is not possible because we use ClassfileAnnotation, which only allows constants. StaticAnnotation would in theory let us use expressions, but that doesn't work for annotating arguments while using named arguments in the annotation due to https://users.scala-lang.org/t/how-to-use-named-arguments-in-scala-user-defined-annotations/4163.

A workaround for this would be to explode the singular @arg annotation:

class arg(val name: String = null,
          val short: Char = 0,
          val doc: String = null,
          val noDefaultName: Boolean = false,
          val positional: Boolean = false) extends ClassfileAnnotation

Into a collection of single-value annotations:

class name(value: String) extends StaticAnnotation
class short(value: Char) extends StaticAnnotation
class doc(value: String) extends StaticAnnotation
class noDefaultName extends StaticAnnotation
class positional extends StaticAnnotation

Using this style, a user would be able to specify things about an argument without needing to use named arguments, allowing us to workaround both problems and provide non-constant runtime values as part of the annotation metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant