Skip to content

Commit

Permalink
Restrict toString to classes only
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Oct 15, 2024
1 parent 994c995 commit 36208a3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/scala/steps/annotation/toString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ final class toString extends MacroAnnotation:
case _: ClassDef if toStringSym.overridingSymbol(tree.symbol).exists =>
report.warning(s"@toString is not necessary since hashcode is defined in ${tree.symbol}")
List(tree)
case cls: ClassDef if cls.symbol.flags.is(Flags.Trait) =>
report.error(s"@toString is not supported in traits")
List(tree)
case cls: ClassDef if cls.symbol.flags.is(Flags.Module) =>
report.error(s"@toString is not supported in object")
List(tree)
case ClassDef(className, ctr, parents, self, body) =>
val cls = tree.symbol

Expand Down

0 comments on commit 36208a3

Please sign in to comment.