Suppose I have a string with a field path of a Scala case class, e.g.
case class A1(x: Int)
case class A(a1: A1)
val x = "a1.x" // field path of "x" in "A"
I use this field path for runtime reflection. The problem is that these classes A and A1 may change and then the field path becomes invalid.
case class A1(x1: Int)
case class A(a1: A1)
val x = "a1.x" // invalid path in "A"
Now I want to validate the field path in compile time like this:
case class A1(x1: Int)
case class A(a1: A1)
val x = FieldPath[A]("a1.x") // compiler error
What is the best way to do it with Scala 2 ? I guess it's doable using Scala 2 macros but I don't know how to do that.