Skip to content

Commit 7406c30

Browse files
Kordyjanliufengyun
andcommitted
Apply suggestions from code review
- now only the first clashing annotation is reported Co-authored-by: Fengyun Liu <[email protected]>
1 parent 3901cb0 commit 7406c30

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/src/dotty/tools/dotc/transform/RepeatableAnnotations.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,20 @@ class RepeatableAnnotations extends MiniPhase:
2929
annsByType.flatMap {
3030
case (_, a :: Nil) => a :: Nil
3131
case (sym, anns) if sym.derivesFrom(defn.ClassfileAnnotationClass) =>
32-
sym.annotations.find(_ matches defn.JavaRepeatableAnnot).flatMap(_.argumentConstant(0)) match
32+
sym.getAnnotation(defn.JavaRepeatableAnnot).flatMap(_.argumentConstant(0)) match
3333
case Some(Constant(containerTpe: Type)) =>
3434
val clashingAnns = annsByType.getOrElse(containerTpe.classSymbol, Nil)
35-
if !clashingAnns.isEmpty then
35+
if clashingAnns.nonEmpty then
3636
// this is the same error javac would raise in this case
37-
val pos = clashingAnns.map(_.tree.srcPos).minBy(_.line)
37+
val pos = clashingAnns.head.tree.srcPos
3838
report.error("Container must not be present at the same time as the element it contains", pos)
3939
Nil
4040
else
4141
val aggregated = JavaSeqLiteral(anns.map(_.tree).toList, TypeTree(sym.typeRef))
4242
Annotation(containerTpe, NamedArg("value".toTermName, aggregated)) :: Nil
4343
case _ =>
44-
val pos = anns.map(_.tree.srcPos).sortBy(_.line).apply(1)
44+
val pos = anns.head.tree.srcPos
4545
report.error("Not repeatable annotation repeated", pos)
4646
Nil
4747
case (_, anns) => anns
4848
}.toList
49-

0 commit comments

Comments
 (0)