Skip to content

Commit df7aa25

Browse files
Merge pull request #10103 from dotty-staging/disallow-interpreation-of-arbitrary-calls-in-paramteres
Disallow interpretation of arbitrary calls in parameters
2 parents 72a8809 + 3b83534 commit df7aa25

File tree

12 files changed

+39
-28
lines changed

12 files changed

+39
-28
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,12 @@ object Splicer {
146146
case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.InternalQuoted_exprQuote =>
147147
// OK
148148

149-
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.QuotedTypeModule_apply =>
149+
case Apply(Select(TypeApply(fn, List(quoted)), nme.apply), _)if fn.symbol == defn.QuotedTypeModule_apply =>
150150
// OK
151151

152152
case Literal(Constant(value)) =>
153153
// OK
154154

155-
case Call(fn, args)
156-
if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package)) ||
157-
fn.symbol.is(Module) || fn.symbol.isStatic ||
158-
(fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic) =>
159-
args.foreach(_.foreach(checkIfValidArgument))
160-
161155
case NamedArg(_, arg) =>
162156
checkIfValidArgument(arg)
163157

tests/neg-macros/i4492/quoted_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
trait Index
3+
4+
object Index {
5+
inline def succ(prev: Index): Unit = ${ '{println("Ok")} } // error
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
object Test {
33
def main(args: Array[String]): Unit = {
4-
Index.succ(null)
4+
Index.succ(null) // error
55
}
66
}

tests/neg-macros/i4493-b.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import scala.quoted._
12
class Index[K]
23
object Index {
34
inline def succ[K](x: K): Unit = ${
4-
implicit val t: quoted.Type[K] = Type[K] // error
5-
'{new Index[K]}
5+
implicit val t: Type[K] = Type[K] // error
6+
'{new Index[K]} // error
67
}
78
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Index[K]
22
object Index {
33
inline def succ[K]: Unit = ${
4-
'{new Index[K]}
4+
'{new Index[K]} // error
55
}
66
}

tests/neg-macros/i4493.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import scala.quoted._
12
class Index[K]
23
object Index {
34
inline def succ[K]: Unit = ${
4-
implicit val t: quoted.Type[K] = Type[K] // error
5-
'{new Index[K]}
5+
implicit val t: Type[K] = Type[K] // error
6+
'{new Index[K]} // error
67
}
78
}

tests/neg-macros/i5547.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
3+
object scalatest {
4+
inline def assert2(condition: => Boolean): Unit =
5+
${ assertImpl('condition, Expr("")) } // error
6+
7+
def assertImpl(condition: Expr[Boolean], clue: Expr[Any])(using QuoteContext): Expr[Unit] =
8+
'{}
9+
}

tests/pos-macros/i4023c/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import scala.quoted._
22
object Macro {
3-
inline def ff[T](x: T): T = ${ impl('x)(Type[T], summon[QuoteContext]) }
3+
inline def ff[T](x: T): T = ${ impl('x) }
44
def impl[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{ $x: $t }
55
}

tests/pos-macros/i5547.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import scala.quoted._
22

33
object scalatest {
44
inline def assert1(condition: => Boolean): Unit =
5-
${assertImpl('condition, '{""})}
6-
7-
inline def assert2(condition: => Boolean): Unit =
8-
${ assertImpl('condition, Expr("")) }
5+
${assertImpl('condition, '{""})}
96

107
def assertImpl(condition: Expr[Boolean], clue: Expr[Any])(using QuoteContext): Expr[Unit] =
118
'{}

tests/run-macros/i4492/quoted_1.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/run-macros/quote-matcher-symantics-2/quoted_1.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ import scala.quoted.unsafe._
44

55
object Macros {
66

7-
inline def liftString(inline a: DSL): String = ${impl(StringNum, 'a)}
7+
inline def liftString(inline a: DSL): String = ${implStringNum('a)}
88

9-
inline def liftCompute(inline a: DSL): Int = ${impl(ComputeNum, 'a)}
9+
private def implStringNum(a: Expr[DSL])(using qctx: QuoteContext): Expr[String] =
10+
impl(StringNum, a)
1011

11-
inline def liftAST(inline a: DSL): ASTNum = ${impl(ASTNum, 'a)}
12+
inline def liftCompute(inline a: DSL): Int = ${implComputeNum('a)}
13+
14+
private def implComputeNum(a: Expr[DSL])(using qctx: QuoteContext): Expr[Int] =
15+
impl(ComputeNum, a)
16+
17+
inline def liftAST(inline a: DSL): ASTNum = ${implASTNum('a)}
18+
19+
private def implASTNum(a: Expr[DSL])(using qctx: QuoteContext): Expr[ASTNum] =
20+
impl(ASTNum, a)
1221

1322
private def impl[T: Type](sym: Symantics[T], a: Expr[DSL])(using qctx: QuoteContext): Expr[T] = {
1423

0 commit comments

Comments
 (0)