Pattern matching over emptyValDef and pendingSuperCall trees

59 views
Skip to first unread message

Den Sh

unread,
Dec 14, 2012, 7:25:28 AM12/14/12
to scala-i...@googlegroups.com
Hello,

I've stumbled upon an unexpected problem with reflection pattern matching:

scala> val u = scala.reflect.runtime.universe
u: scala.reflect.api.JavaUniverse = scala.reflect.runtime.JavaUniverse@18b679e1

scala> u.emptyValDef match { case u.emptyValDef => }
<console>:20: error: stable identifier required, but u.emptyValDef found.
 Note that value emptyValDef is not stable because its type, => u.ValDef, is volatile.
              u.emptyValDef match { case u.emptyValDef => }
                                           ^

scala> u.pendingSuperCall match { case u.pendingSuperCall => }
<console>:20: error: stable identifier required, but u.pendingSuperCall found.
 Note that value pendingSuperCall is not stable because its type, => u.Apply, is volatile.
              u.pendingSuperCall match { case u.pendingSuperCall => }
                                                ^


Can anything be done to aid pattern matching over this values ?

Adriaan Moors

unread,
Dec 14, 2012, 1:35:33 PM12/14/12
to scala-i...@googlegroups.com
ah yes, I wonder if patterns need to exclude identifiers that would be stable if it wasn't for their volatile type
It's unsound to select types on a prefix with a volatile type, but it should be fine to compare it for equality.



in the short term, an extractor could help I suppose
Reply all
Reply to author
Forward
0 new messages