ScalaNullSafe icon indicating copy to clipboard operation
ScalaNullSafe copied to clipboard

Make macro work in place of anonymous function

Open ryanstull opened this issue 1 year ago • 2 comments

The macro should work in the following situation:

case class A(b: B)
case class B(c: C)
case class C(d: D)
case class D(s: String)

def expectFunction[T](f: A => T): T = ...

expectFunction(?(_.b.c.d.s))

Current it works if you do:

expectFunction(a => ?(a.b.c.d.s))

but it would be nice to be able to use the simpler syntax

ryanstull avatar Sep 27 '24 22:09 ryanstull

Could ? be an extension function instead? That would seemingly solve the lambda case as well, as expectFunction(_.b.c.d.s.?). I guess that may not be portable to Scala 2...

kubukoz avatar Mar 16 '25 19:03 kubukoz

Hmmm that potentially could work for Scala 3, but I'd like to keep the syntax consistent between versions. I probably just have to dig a bit deeper into the AST of the anonymous function syntax

ryanstull avatar Mar 25 '25 14:03 ryanstull