Skip to content

Commit 8f5556e

Browse files
committed
Walkaround for exception in Term.underlyingArgument
1 parent d4d98ba commit 8f5556e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tests/run-with-compiler/i5941/macro_1.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,35 @@ object Lens {
2121
def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] =
2222
Term.Select.overloaded(obj.unseal, "copy", Nil, Term.NamedArg(field, value.unseal) :: Nil).seal[S]
2323

24-
getter.unseal.underlyingArgument match {
25-
case Term.Block(
26-
DefDef(_, Nil, (param :: Nil) :: Nil, _, Some(Term.Select(o, field))) :: Nil,
27-
Term.Lambda(meth, _)
28-
) =>
24+
// exception: getter.unseal.underlyingArgument
25+
getter.unseal match {
26+
case Term.Inlined(
27+
None, Nil,
28+
Term.Block(
29+
DefDef(_, Nil, (param :: Nil) :: Nil, _, Some(Term.Select(o, field))) :: Nil,
30+
Term.Lambda(meth, _)
31+
)
32+
) if o.symbol == param.symbol =>
2933
'{
3034
val setter = (t: T) => (s: S) => ~setterBody('(s), '(t), field)
3135
apply(~getter)(setter)
3236
}
37+
case _ =>
38+
throw new QuoteError("Unsupported syntax. Example: `GenLens[Address](_.streetNumber)`")
3339
}
3440
}
3541
}
3642

3743
object GenLens {
3844
/** case class Address(streetNumber: Int, streetName: String)
3945
*
40-
* Lens.gen[Address, Int](_.streetNumber) ~~>
46+
* GenLens[Address](_.streetNumber) ~~>
4147
*
4248
* Lens[Address, Int](_.streetNumber)(n => a => a.copy(streetNumber = n))
4349
*/
4450

4551
def apply[S] = new MkGenLens[S]
4652
class MkGenLens[S] {
47-
inline def apply[T](get: S => T): Lens[S, T] = ~Lens.impl('(get))
53+
inline def apply[T](get: => (S => T)): Lens[S, T] = ~Lens.impl('(get))
4854
}
4955
}

0 commit comments

Comments
 (0)