File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed
compiler/src/dotty/tools/dotc/typer
library/src/scala/compiletime/testing
run-macros/reflect-inline Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -283,11 +283,16 @@ object Inliner {
283
283
assert(tree.symbol == defn.CompiletimeTesting_typeChecks || tree.symbol == defn.CompiletimeTesting_typeCheckErrors )
284
284
def stripTyped (t : Tree ): Tree = t match {
285
285
case Typed (t2, _) => stripTyped(t2)
286
+ case Inlined (_, Nil , t2) => stripTyped(t2)
286
287
case _ => t
287
288
}
288
289
289
290
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
+
291
296
ConstFold (underlyingCodeArg).tpe.widenTermRefExpr match {
292
297
case ConstantType (Constant (code : String )) =>
293
298
val source2 = SourceFile .virtual(" tasty-reflect" , code)
@@ -303,7 +308,7 @@ object Inliner {
303
308
res ++= typerErrors.map(e => ErrorKind .Typer -> e)
304
309
res.toList
305
310
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)
307
312
Nil
308
313
}
309
314
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ package testing
9
9
*
10
10
* The code should be a sequence of expressions or statements that may appear in a block.
11
11
*/
12
- inline def typeChecks (inline code : String ): Boolean =
12
+ transparent inline def typeChecks (inline code : String ): Boolean =
13
13
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
14
14
error(" Compiler bug: `typeChecks` was not checked by the compiler" )
15
15
@@ -26,6 +26,6 @@ inline def typeChecks(inline code: String): Boolean =
26
26
*
27
27
* The code should be a sequence of expressions or statements that may appear in a block.
28
28
*/
29
- inline def typeCheckErrors (inline code : String ): List [Error ] =
29
+ transparent inline def typeCheckErrors (inline code : String ): List [Error ] =
30
30
// implemented in package dotty.tools.dotc.typer.Inliner.Intrinsics
31
31
error(" Compiler bug: `typeCheckErrors` was not checked by the compiler" )
Original file line number Diff line number Diff line change
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()
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import api._
2
2
3
3
object Test {
4
4
def main (args : Array [String ]): Unit = {
5
- val a : String = " 5"
5
+ inline val a = " 5"
6
6
assert(typeChecks(" |1 + 1" .stripMargin))
7
7
assert(scala.compiletime.testing.typeChecks(" |1 + 1" .stripMargin))
8
8
assert((" |3 + " + a).stripMargin == " 3 + 5" )
You can’t perform that action at this time.
0 commit comments