Skip to content

Commit

Permalink
Do not accept splices and holes in annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Nov 6, 2024
1 parent d8cfc49 commit 2cc6ea4
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,6 @@ trait Checking {
case Typed(expr, _) => validAnnotArg(expr)
// TODO(mbovel): should probably be handled by `tpd.allTermArguments` instead.
case NamedArg(_, arg) => validAnnotArg(arg)
// TODO(mbovel): we should probably not allow `Splice` and `Hole`.
// How to encode them as types?
// When removing those cases, tests/pos-macros/i7519b.scala and
// tests/pos-macros/i7052.scala fail.
case Splice(_) => true
case Hole(_, _, _, _) => true
case _ => false

/** 1. Check that all case classes that extend `scala.reflect.Enum` are `enum` cases
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i7052.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import scala.quoted.*
class Test {
def foo(str: String)(using Quotes) = '{
@deprecated(str, "") // error
@deprecated(str, "") // error: not a valid annotation
def bar = ???
}
}
2 changes: 1 addition & 1 deletion tests/neg-macros/i7052b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Test {
val qctx: Quotes = ???
given qctx.type = qctx
'{
@deprecated(str, "") // error
@deprecated(str, "") // error: not a valid annotation
def bar = ???
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import scala.quoted.*
class Test {
def foo(str: Expr[String])(using Quotes) = '{
@deprecated($str, "")
@deprecated($str, "") // error: not a valid annotation
def bar = ???
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ inline def quote[T]: Quoted[T] = ${ quoteImpl[T] }

def quoteImpl[T: Type](using Quotes): Expr[Quoted[T]] = {
val value: Expr[Int] = '{ 42 }
'{ new Quoted[T @Annot($value)] }
'{ new Quoted[T @Annot($value)] } // error: not a valid annotation
}

0 comments on commit 2cc6ea4

Please sign in to comment.