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

Add support for type parameters in annotations #1051

Closed
pgrandjean opened this issue Oct 26, 2020 · 6 comments · Fixed by #1058
Closed

Add support for type parameters in annotations #1051

pgrandjean opened this issue Oct 26, 2020 · 6 comments · Fixed by #1058
Labels

Comments

@pgrandjean
Copy link
Contributor

pgrandjean commented Oct 26, 2020

Follow up on issue #922 and pull request #925. I would like to add support for type parameters in annotations, both variable and type annotations. For example, define an annotation such as:

case class MyAnnotation[T](t: T) extends scala.annotation.StaticAnnotation

The out type of Annotations and TypeAnnotations would have the complete "reference" to type T.

@pgrandjean
Copy link
Contributor Author

pgrandjean commented Nov 2, 2020

Moreover, what about generalizing Annotations to return all annotations instead of just one annotation type A? Example:

case class HelloWorld(
  field1: String @A11[T111, T112, ..., T11n] @A12[T121, T122, ..., T12n] ... @A1m[T1m1, T1m2, ..., T1mn],
  field2: String @A21[T211, T212, ..., T21n] @A22[T221, T222, ..., T22n] ... @A2m[T2m1, T2m2, ..., T2mn],
  ...,
  fieldk: String @Ak1[Tk11, Tk12, ..., Tk1n] @Ak2[Tk21, Tk22, ..., Tk2n] ... @Akm[Tkm1, Tkm2, ..., Tkmn],
)

Would be nice to have a single macro to extract in one pass all annotations, no?

The trait would look like the following:

trait AllAnnotations[T] extends DepFn0 with Serializable {
  // no more type A
  type Out <: HList
}

For the example above, the Out type would be an HList of HLists:

(A11[T111, T112, ..., T11n] :: A12[T121, T122, ..., T12n] :: ... :: A1m[T1m1, T1m2, ..., T1mn] :: HNil) ::
(A21[T211, T212, ..., T21n] :: A22[T221, T222, ..., T22n] :: ... :: A2m[T2m1, T2m2, ..., T2mn] :: HNil) ::
... ::
(Ak1[Tk11, Tk12, ..., Tk1n] :: Ak2[Tk21, Tk22, ..., Tk2n] :: ... :: Akm[Tkm1, Tkm2, ..., Tkmn] :: HNil) :: HNil

@alexarchambault
Copy link
Collaborator

AFAIC, I think it would be nice to have.

@pgrandjean
Copy link
Contributor Author

I have a working prototype. Will try to submit a PR in the coming days.

joroKr21 added a commit that referenced this issue Apr 27, 2021
Add support to extract all variable or type annotations (issue #1051)
@pgrandjean
Copy link
Contributor Author

@joroKr21 just wondering, is this going to work with Scala 3?

@joroKr21
Copy link
Collaborator

@joroKr21 just wondering, is this going to work with Scala 3?

The Scala 3 story is a bit messy for shapeless because it uses a lot of macros.

This particular implementation won't work on Scala 3.
There is Shapeless 3 which works only with Scala 3 on the shapeless-3 branch.
I don't know much about it yet, so I can't say what it offers in terms of annotations.
Separately from that we have an issue to port shapeless 2 in some form to Scala 3: #1043
But nobody is working on that at the moment.

@joroKr21
Copy link
Collaborator

At least there is a step in that direction: #1019
Next would be, write a scalafix rule to replace Lazy and Strict with by-name implicits in the source code.

joroKr21 added a commit that referenced this issue Apr 27, 2021
Add support to extract all variable or type annotations (issue #1051)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants