It seems compiler adds path into name when creates anonymous classes. Your example (pretty interesting in some other sense by the way) may be simplified down to:
def m1(s: String) = s
def m2: String => String = s => s
val ss: Seq[String => String] = Seq(m1, m2)
ss map (_.getClass.getSimpleName)
Which produces:
res28: Seq[String] = List(anonfun$1, anonfun$m2$1)
Without Seq:
(m1 _).getClass.getSimpleName
res34: String = anonfun$1
m2.getClass.getSimpleName
res35: String = anonfun$m2$1
Luckily m1
in Seq is equivalent to m1 _
, and m2
is equivalent to method application.
What about names - compiler adds path to autogenerated classes, so, top-scope m1
turns to anonfun$1
(anonfun is default prefix for generated classes for functions), and because m2
returns function from inside, that function gets one more element in path (name).
Interestingly, this weird thing:
def a() = {
def b() = {
def c() = {
def d(): String => String = s => s
d()
}
c()
}
b()
}
Has name:
a().getClass.getSimpleName
res30: String = anonfun$d$1$1
So, no trace of a, b, c! So, it's somewhat complicated, I tried but couldn't have found the exact choice and patterns of naming in compiler source, though reading was interesting.