Skip to content

Commit da59cad

Browse files
committed
Fix missing inlining in checkCompiles
1 parent d02b865 commit da59cad

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,16 @@ object Inliner {
283283
assert(tree.symbol == defn.CompiletimeTesting_typeChecks || tree.symbol == defn.CompiletimeTesting_typeCheckErrors)
284284
def stripTyped(t: Tree): Tree = t match {
285285
case Typed(t2, _) => stripTyped(t2)
286+
case Inlined(_, Nil, t2) => stripTyped(t2)
286287
case _ => t
287288
}
288289

289290
val Apply(_, codeArg :: Nil) = tree
290-
val underlyingCodeArg = stripTyped(codeArg.underlying)
291+
val underlyingCodeArg =
292+
val codeArg1 = stripTyped(codeArg.underlying)
293+
if Inliner.isInlineable(codeArg1) then stripTyped(Inliner.inlineCall(codeArg1))
294+
else codeArg1
295+
291296
ConstFold(underlyingCodeArg).tpe.widenTermRefExpr match {
292297
case ConstantType(Constant(code: String)) =>
293298
val source2 = SourceFile.virtual("tasty-reflect", code)
@@ -303,7 +308,7 @@ object Inliner {
303308
res ++= typerErrors.map(e => ErrorKind.Typer -> e)
304309
res.toList
305310
case t =>
306-
report.error(em"argument to compileError must be a statically known String but was: $tree", underlyingCodeArg.srcPos)
311+
report.error(em"argument to ${tree.symbol} must be a statically known String but was: $codeArg", codeArg.srcPos)
307312
Nil
308313
}
309314

library/src/scala/compiletime/testing/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package testing
99
*
1010
* The code should be a sequence of expressions or statements that may appear in a block.
1111
*/
12-
inline def typeChecks(inline code: String): Boolean =
12+
transparent inline def typeChecks(inline code: String): Boolean =
1313
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
1414
error("Compiler bug: `typeChecks` was not checked by the compiler")
1515

@@ -26,6 +26,6 @@ inline def typeChecks(inline code: String): Boolean =
2626
*
2727
* The code should be a sequence of expressions or statements that may appear in a block.
2828
*/
29-
inline def typeCheckErrors(inline code: String): List[Error] =
29+
transparent inline def typeCheckErrors(inline code: String): List[Error] =
3030
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
3131
error("Compiler bug: `typeCheckErrors` was not checked by the compiler")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Test:
2+
def test: Unit =
3+
assert2(scala.compiletime.testing.typeChecks(stripMargin("|1 + 1")))
4+
5+
inline def stripMargin(inline x: String): String = x
6+
7+
transparent inline def assert2(inline assertion: Boolean): Unit =
8+
if !assertion then scala.runtime.Scala3RunTime.assertFailed()

tests/run-macros/reflect-inline/test_2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import api._
22

33
object Test {
44
def main(args: Array[String]): Unit = {
5-
val a: String = "5"
5+
inline val a = "5"
66
assert(typeChecks("|1 + 1".stripMargin))
77
assert(scala.compiletime.testing.typeChecks("|1 + 1".stripMargin))
88
assert(("|3 + " + a).stripMargin == "3 + 5")

0 commit comments

Comments
 (0)