Skip to content

Commit ffd8f5a

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Add regression test for #19909
Closes #19909 Probably fixed by #19645 [Cherry-picked 2a97cb4]
1 parent 64996f4 commit ffd8f5a

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

tests/pos-macros/i19909/Macro_1.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package examples.select
2+
3+
import scala.language.dynamics
4+
import scala.quoted.*
5+
6+
case class Wrapper[A](inner: A) extends Dynamic:
7+
transparent inline def selectDynamic(inline name: String) =
8+
${selectDynamicImpl('inner, 'name)}
9+
10+
def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] =
11+
import quotes.reflect.*
12+
Select.unique(inner.asTerm, name.valueOrAbort).asExpr

tests/pos-macros/i19909/Test_2.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package examples.select
2+
3+
4+
import scala.language.dynamics
5+
import examples.select.Wrapper
6+
7+
object Dynamic0:
8+
9+
@main
10+
def runTimeError =
11+
12+
val w = Wrapper(Option(1))
13+
println(w.isEmpty)
14+
15+
end Dynamic0

tests/pos-macros/i19909b/Macro.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package examples.select
2+
3+
import scala.language.dynamics
4+
import scala.quoted.*
5+
6+
case class Wrapper[A](inner: A) extends Dynamic:
7+
transparent inline def selectDynamic(inline name: String) =
8+
${selectDynamicImpl('inner, 'name)}
9+
10+
def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] =
11+
import quotes.reflect.*
12+
Select.unique(inner.asTerm, name.valueOrAbort).asExpr

tests/pos-macros/i19909b/Test.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package examples.select
2+
3+
4+
import scala.language.dynamics
5+
import examples.select.Wrapper
6+
7+
object Dynamic0:
8+
9+
@main
10+
def runTimeError =
11+
12+
val w = Wrapper(Option(1))
13+
println(w.isEmpty)
14+
15+
end Dynamic0

0 commit comments

Comments
 (0)