-
Notifications
You must be signed in to change notification settings - Fork 170
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
Fix support of fieldName annotations #773
Fix support of fieldName annotations #773
Conversation
Fix ignoring non-first fieldName annotations at the field declarations
@@ -256,7 +256,7 @@ private case class DeriveSchema()(using val ctx: Quotes) { | |||
tpe.asType | |||
} | |||
val annotations = paramAnns.getOrElse(label, List.empty) | |||
val nameExpr = annotations.collectFirst { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think more the one annotation of the same kind is using the lib wrong. I would keep the old impl, since it is less complicated. You annotate twice? Your problem. Just don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed solution is a workaround for reverse order of annotations in Scala 3 macros.
The better solution would be throwing a compile-time error during derivation or/and runtime error when calculating fieldName
value in Schema.Field
instances
val fieldName: String = annotations.collectFirst { | ||
case f: fieldName => f.name | ||
}.getOrElse(name) | ||
|
||
val nameAndAliases: scala.collection.immutable.Set[String] = | ||
annotations.foldLeft(scala.collection.immutable.Set(fieldName)) { (acc, annotation) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a difference besides making it a fold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It avoids reusing of an old (renamed) field name as an alias
Fix using of fieldName annotations to rename fields (not aliasing)
Fix ignoring non-first fieldName annotations at the field declarations