Skip to content

Commit 622e8c3

Browse files
committed
Fix annotation applicability checking
1 parent 4df2db1 commit 622e8c3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import util.Spans.Span
1010

1111
object Annotations {
1212

13+
def annotClass(tree: Tree) given Context =
14+
if (tree.symbol.isConstructor) tree.symbol.owner
15+
else tree.tpe.typeSymbol
16+
1317
abstract class Annotation {
1418
def tree(implicit ctx: Context): Tree
1519

16-
def symbol(implicit ctx: Context): Symbol =
17-
if (tree.symbol.isConstructor) tree.symbol.owner
18-
else tree.tpe.typeSymbol
20+
def symbol(implicit ctx: Context): Symbol = annotClass(tree)
1921

2022
def matches(cls: Symbol)(implicit ctx: Context): Boolean = symbol.derivesFrom(cls)
2123

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,9 @@ trait Checking {
11391139
/** check that annotation `annot` is applicable to symbol `sym` */
11401140
def checkAnnotApplicable(annot: Tree, sym: Symbol) given (ctx: Context): Boolean =
11411141
!ctx.reporter.reportsErrorsFor { implicit ctx =>
1142+
val annotCls = Annotations.annotClass(annot)
11421143
val pos = annot.sourcePos
1143-
if (annot.symbol == defn.MainAnnot) {
1144+
if (annotCls == defn.MainAnnot) {
11441145
if (!sym.isRealMethod)
11451146
ctx.error(em"@main annotation cannot be applied to $sym", pos)
11461147
if (!sym.owner.is(Module) || !sym.owner.isStatic)

0 commit comments

Comments
 (0)