Skip to content

Commit f56760a

Browse files
authored
Merge pull request #14090 from dotty-staging/fix-14062
Reject empty target names
2 parents 8e1054e + c321c81 commit f56760a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import ErrorReporting.errorTree
2020
import rewrites.Rewrites.patch
2121
import util.Spans.Span
2222
import Phases.refchecksPhase
23+
import Constants.Constant
2324

2425
import util.SrcPos
2526
import util.Spans.Span
@@ -1204,13 +1205,14 @@ trait Checking {
12041205
/** Check arguments of compiler-defined annotations */
12051206
def checkAnnotArgs(tree: Tree)(using Context): tree.type =
12061207
val cls = Annotations.annotClass(tree)
1207-
def needsStringLit(arg: Tree) =
1208-
report.error(em"@${cls.name} needs a string literal as argument", arg.srcPos)
12091208
tree match
12101209
case Apply(tycon, arg :: Nil) if cls == defn.TargetNameAnnot =>
12111210
arg match
1211+
case Literal(Constant("")) =>
1212+
report.error(em"target name cannot be empty", arg.srcPos)
12121213
case Literal(_) => // ok
1213-
case _ => needsStringLit(arg)
1214+
case _ =>
1215+
report.error(em"@${cls.name} needs a string literal as argument", arg.srcPos)
12141216
case _ =>
12151217
tree
12161218

tests/neg/i14062.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import annotation.*
2+
3+
object Test:
4+
5+
@targetName("") // error
6+
def foo = println("ok")
7+
8+
foo
9+
10+

0 commit comments

Comments
 (0)