From a5b8ffcf2f5f940e1bf34b1fb5aa7b7362309ae5 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 12 Feb 2021 13:53:55 +0100 Subject: [PATCH] Add regression test Closes #11386 --- tests/neg-macros/i11386.check | 13 +++++++++++++ tests/neg-macros/i11386/Macro_1.scala | 18 ++++++++++++++++++ tests/neg-macros/i11386/Test_2.scala | 13 +++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/neg-macros/i11386.check create mode 100644 tests/neg-macros/i11386/Macro_1.scala create mode 100644 tests/neg-macros/i11386/Test_2.scala diff --git a/tests/neg-macros/i11386.check b/tests/neg-macros/i11386.check new file mode 100644 index 000000000000..0377ca6389db --- /dev/null +++ b/tests/neg-macros/i11386.check @@ -0,0 +1,13 @@ + +-- Error: tests/neg-macros/i11386/Test_2.scala:6:10 -------------------------------------------------------------------- +6 | dummy(0) // error + | ^ + | test + | This location contains code that was inlined from Test_2.scala:6 + | This location contains code that was inlined from Macro_1.scala:7 +-- Error: tests/neg-macros/i11386/Test_2.scala:8:20 -------------------------------------------------------------------- +8 | dummy(int2String(0)) // error + | ^^^^^^^^^^^^^ + | test + | This location contains code that was inlined from Test_2.scala:8 + | This location contains code that was inlined from Macro_1.scala:7 diff --git a/tests/neg-macros/i11386/Macro_1.scala b/tests/neg-macros/i11386/Macro_1.scala new file mode 100644 index 000000000000..8d6e6f3d029a --- /dev/null +++ b/tests/neg-macros/i11386/Macro_1.scala @@ -0,0 +1,18 @@ +import scala.language.implicitConversions +import scala.quoted._ + +object test { + + inline implicit def int2String(inline i: Int): String = { + notNull(i) + String.valueOf(i) + } + + inline def notNull(inline i: Int): Unit = ${notNullImpl('i)} + + def notNullImpl(expr: Expr[Int])(using quotes: Quotes): Expr[Unit] = { + println(expr.show) + expr.value.foreach(i => if(i == 0) quotes.reflect.report.error("test")) + '{()} + } +} diff --git a/tests/neg-macros/i11386/Test_2.scala b/tests/neg-macros/i11386/Test_2.scala new file mode 100644 index 000000000000..c5b7f7fea21b --- /dev/null +++ b/tests/neg-macros/i11386/Test_2.scala @@ -0,0 +1,13 @@ +import test._ + +object Main { + + @main def dottyTest(): Unit = { + dummy(0) // error + dummy(1) + dummy(int2String(0)) // error + dummy(int2String(1)) + } + + def dummy(msg: String): Unit = println(msg) //A simple dummy method to call implicitly test.int2String +}