Skip to content

Commit b5d9ef3

Browse files
Merge pull request #5215 from dotty-staging/fix-#5198
Fix #5188: See through annotations and typevars when computing argume…
2 parents 58fa2dd + 94987ea commit b5d9ef3

File tree

8 files changed

+62
-25
lines changed

8 files changed

+62
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class TypeApplications(val self: Type) extends AnyVal {
461461
* otherwise return Nil.
462462
* Existential types in arguments are returned as TypeBounds instances.
463463
*/
464-
final def argInfos(implicit ctx: Context): List[Type] = self match {
464+
final def argInfos(implicit ctx: Context): List[Type] = self.stripTypeVar.stripAnnots match {
465465
case AppliedType(tycon, args) => args
466466
case _ => Nil
467467
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,10 @@ object Splicer {
318318

319319
case Inlined(EmptyTree, Nil, expansion) => interpretTree(expansion)
320320

321-
case Typed(SeqLiteral(elems, _), _) =>
321+
case Typed(expr, _) =>
322+
interpretTree(expr)
323+
324+
case SeqLiteral(elems, _) =>
322325
interpretVarargs(elems.map(e => interpretTree(e)))
323326

324327
case _ =>

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -678,29 +678,39 @@ trait Checking {
678678
val purityLevel = if (isFinal) Idempotent else Pure
679679
tree.tpe.widenTermRefExpr match {
680680
case tp: ConstantType if exprPurity(tree) >= purityLevel => // ok
681-
case tp =>
682-
def isCaseClassApply(sym: Symbol): Boolean =
683-
sym.name == nme.apply && sym.is(Synthetic) && sym.owner.is(Module) && sym.owner.companionClass.is(Case)
684-
def isCaseClassNew(sym: Symbol): Boolean =
685-
sym.isPrimaryConstructor && sym.owner.is(Case) && sym.owner.isStatic
686-
def isCaseObject(sym: Symbol): Boolean = {
687-
// TODO add alias to Nil in scala package
688-
sym.is(Case) && sym.is(Module)
689-
}
690-
val allow =
691-
ctx.erasedTypes ||
692-
ctx.inInlineMethod ||
693-
(tree.symbol.isStatic && isCaseObject(tree.symbol) || isCaseClassApply(tree.symbol)) ||
694-
isCaseClassNew(tree.symbol)
695-
if (!allow) ctx.error(em"$what must be a known value", tree.pos)
696-
else {
697-
def checkArgs(tree: Tree): Unit = tree match {
698-
case Apply(fn, args) =>
699-
args.foreach(arg => checkInlineConformant(arg, isFinal, what))
700-
checkArgs(fn)
701-
case _ =>
702-
}
703-
checkArgs(tree)
681+
case _ =>
682+
tree match {
683+
case Typed(expr, _) =>
684+
checkInlineConformant(expr, isFinal, what)
685+
case SeqLiteral(elems, _) =>
686+
elems.foreach(elem => checkInlineConformant(elem, isFinal, what))
687+
case Apply(fn, List(arg)) if defn.WrapArrayMethods().contains(fn.symbol) =>
688+
checkInlineConformant(arg, isFinal, what)
689+
case _ =>
690+
def isCaseClassApply(sym: Symbol): Boolean =
691+
sym.name == nme.apply && sym.is(Synthetic) && sym.owner.is(Module) && sym.owner.companionClass.is(Case)
692+
def isCaseClassNew(sym: Symbol): Boolean =
693+
sym.isPrimaryConstructor && sym.owner.is(Case) && sym.owner.isStatic
694+
def isCaseObject(sym: Symbol): Boolean = {
695+
// TODO add alias to Nil in scala package
696+
sym.is(Case) && sym.is(Module)
697+
}
698+
val allow =
699+
ctx.erasedTypes ||
700+
ctx.inInlineMethod ||
701+
(tree.symbol.isStatic && isCaseObject(tree.symbol) || isCaseClassApply(tree.symbol)) ||
702+
isCaseClassNew(tree.symbol)
703+
704+
if (!allow) ctx.error(em"$what must be a known value", tree.pos)
705+
else {
706+
def checkArgs(tree: Tree): Unit = tree match {
707+
case Apply(fn, args) =>
708+
args.foreach(arg => checkInlineConformant(arg, isFinal, what))
709+
checkArgs(fn)
710+
case _ =>
711+
}
712+
checkArgs(tree)
713+
}
704714
}
705715
}
706716
}

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ i4803f
2222
i4947b
2323
i5119
2424
i5119b
25+
i5188a
2526
inline-varargs-1
2627
implicitShortcut
2728
inline-case-objects

tests/pos/i5188.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
inline def sum(inline args: Int*): Int = 0
3+
sum(1, 2, 3)
4+
}

tests/run/i5188a.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0
2+
1
3+
3
4+
6

tests/run/i5188a/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object Lib {
4+
inline def sum(inline args: Int*): Int = ~impl(args: _*)
5+
def impl(args: Int*): Expr[Int] = args.sum.toExpr
6+
}

tests/run/i5188a/Test_2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
println(Lib.sum())
5+
println(Lib.sum(1))
6+
println(Lib.sum(1, 2))
7+
println(Lib.sum(1, 2, 3))
8+
}
9+
}

0 commit comments

Comments
 (0)