Skip to content

Commit 853aa87

Browse files
Merge pull request #12254 from dotty-staging/fix-#12253
Add regression test
2 parents 6b9ee58 + 2cc4488 commit 853aa87

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/pos-macros/i12253/Macro_1.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
import scala.quoted.*
3+
import deriving.*, compiletime.*
4+
5+
object MacroUtils:
6+
transparent inline def extractNameFromSelector[To, T](inline code: To => T) = ${extractNameFromSelectorImpl('code)}
7+
8+
def extractNameFromSelectorImpl[To: Type, T: Type](code: Expr[To => T])(using Quotes): Expr[String] =
9+
import quotes.reflect.*
10+
code.asTerm match
11+
case InlinedLambda(_, Select(_, name)) => Expr(name)
12+
case t => Expr("")
13+
14+
object InlinedLambda:
15+
def unapply(using Quotes)(arg: quotes.reflect.Term): Option[(List[quotes.reflect.ValDef], quotes.reflect.Term)] =
16+
import quotes.reflect.*
17+
arg match
18+
case Inlined(_, _, Lambda(vals, term)) => Some((vals, term))
19+
case Inlined(_, _, nested) => InlinedLambda.unapply(nested)
20+
case t => None
21+
end InlinedLambda
22+
23+
end MacroUtils
24+

tests/pos-macros/i12253/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Usage:
2+
case class Bar(x: Int, y: String, z: (Double, Double))
3+
MacroUtils.extractNameFromSelector[Bar, String](_.y + "abc")
4+
end Usage

0 commit comments

Comments
 (0)