question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[documentation] Custom StaticAnnotation not represented on field Symbol

See original GitHub issue

Compiler version

3.1.2-RC1-bin-20211022-f7abd32-NIGHTLY

Minimized code

import scala.quoted.*

final class Ann extends scala.annotation.StaticAnnotation

case class Foo(
    @Ann @transient bar: String,
    lorem: Int)

  inline def foo[T]: Unit = ${ fooImpl[T] }

  private def fooImpl[T: Type](using q: Quotes): Expr[Unit] = {
    import q.reflect.*

    val tpe = TypeRepr.of[T]
    val annots =
      tpe.typeSymbol.declaredFields.flatMap(_.annotations).mkString(", ")

    '{ println("annotations = " + ${ Expr(annots) }) }
  }

Output

annotations = Apply(Select(New(Ident(transient)),<init>),List())

Expectation

Custom StaticAnnotation Ann should be resolved (and so printed there)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cchantepcommented, Nov 11, 2021

I mean at least adding a @see in StaticAnnotation and/or Annotation to meta indicating that it could be helpful to define the required retention. Otherwise you need to already know of @meta.

1reaction
KacperFKorbancommented, Nov 10, 2021

The annotation is on the primary constructor parameter. It can be accessed like this:

import scala.quoted.*

final class Ann extends scala.annotation.StaticAnnotation

case class Foo(
  @Ann @transient bar: String,
  lorem: Int
)

inline def foo[T]: Unit = ${ fooImpl[T] }

private def fooImpl[T: Type](using q: Quotes): Expr[Unit] = {
  import q.reflect.*

  val tpe = TypeRepr.of[T]
  val annots =
    tpe.typeSymbol.primaryConstructor.paramSymss.flatten.flatMap(_.annotations).mkString(", ")

  '{ println("annotations = " + ${ Expr(annots) }) }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Field symbol as a work area - SAP Community
Statically, field symbols or interface parameters can be used in all oper-and positions that are not excluded by their type with one exception:...
Read more >
Scala returns no annotations for a field - Stack Overflow
For any reason that I do not know, if I write a space at the end of the TermName, then it returns the...
Read more >
Annotations, Names, Scopes, and More - Scala Documentation
A custom annotation type can be made persistent by inheriting from scala.annotation.StaticAnnotation or scala.annotation.ClassfileAnnotation .
Read more >
SAP Annotations for OData Version 2.0 - GitHub Pages
If updatability can change per entity or based on the entities' state, do not use this static annotation and use sap:field-control instead.
Read more >
Annotations - SuperSTAR Documentation
You can enable annotations for a field (for example: Gender), a field value (for ... in a relational database called the static annotation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found