Skip to content

Commit aaca02e

Browse files
Merge pull request #11391 from dotty-staging/fix-#11386
Add regression test
2 parents 3d85473 + a5b8ffc commit aaca02e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

tests/neg-macros/i11386.check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
-- Error: tests/neg-macros/i11386/Test_2.scala:6:10 --------------------------------------------------------------------
3+
6 | dummy(0) // error
4+
| ^
5+
| test
6+
| This location contains code that was inlined from Test_2.scala:6
7+
| This location contains code that was inlined from Macro_1.scala:7
8+
-- Error: tests/neg-macros/i11386/Test_2.scala:8:20 --------------------------------------------------------------------
9+
8 | dummy(int2String(0)) // error
10+
| ^^^^^^^^^^^^^
11+
| test
12+
| This location contains code that was inlined from Test_2.scala:8
13+
| This location contains code that was inlined from Macro_1.scala:7

tests/neg-macros/i11386/Macro_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.language.implicitConversions
2+
import scala.quoted._
3+
4+
object test {
5+
6+
inline implicit def int2String(inline i: Int): String = {
7+
notNull(i)
8+
String.valueOf(i)
9+
}
10+
11+
inline def notNull(inline i: Int): Unit = ${notNullImpl('i)}
12+
13+
def notNullImpl(expr: Expr[Int])(using quotes: Quotes): Expr[Unit] = {
14+
println(expr.show)
15+
expr.value.foreach(i => if(i == 0) quotes.reflect.report.error("test"))
16+
'{()}
17+
}
18+
}

tests/neg-macros/i11386/Test_2.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test._
2+
3+
object Main {
4+
5+
@main def dottyTest(): Unit = {
6+
dummy(0) // error
7+
dummy(1)
8+
dummy(int2String(0)) // error
9+
dummy(int2String(1))
10+
}
11+
12+
def dummy(msg: String): Unit = println(msg) //A simple dummy method to call implicitly test.int2String
13+
}

0 commit comments

Comments
 (0)