I'm looking for a way to find values (or their classes) that are captured by lambda (for serialization - something like Spark) in Scala 3 (I don't need Scala 2 support):
val a = "abc"
val f = () => a + "xyz"
serialize(f) // Should detect a / String as captured value
Doing this in runtime is kinda easy (iterating over f.getClass.getDeclaredFields), but I would like to do it in compile time.
I was trying to inspect time of lambda in Macro, but it's detected as plain scala.Function0 without any interesting info.
I wonder if I can do some tree inspection, but I would really like to avoid that - I feel like I would have to copy compiler internals to catch all edge cases.
Try the following macro
Usage: