Skip to content

Commit 41ac572

Browse files
committed
SI-9319 Avoid "filename too long" errors for anon functions
Under -Ydelambdafy:method, the name of the anonymous class is derived from the names of the original enclosing class and term of the function. However no effort is made to conform to the `-Xmaxclassname` setting when constructing the class name from the components. Recently, in 029cce7, I changed uncurry to selectively fallback to the old method of emitting lambdas when we detect that `-Ydelambdafy:method` would subvert specialization. As a result of this, we could now have a delambdafy translated function enclosed in an anonymous class representing an old-style function. If that function, in turn, is heavily nested, its long name now contributes a long suffix to the delambdafy class's name. This led to a "filename too long" error in `run/kmpSliceSearch.scala`. I have extract the essence of the failure in `pos/t9319.scala`. I then changed delambdafy to use the unexpanded names of the owners rather than the full name. This makes things work as expected. I haven't further protected against pathological cases, given that in 2.12.x and indylambda, we won't ever emit these classes.
1 parent 47d89a4 commit 41ac572

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/compiler/scala/tools/nsc/transform/Delambdafy.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
209209
// - reinstate the assertion in `Erasure.resolveAnonymousBridgeClash`
210210
val suffix = nme.DELAMBDAFY_LAMBDA_CLASS_NAME + "$" + (
211211
if (funOwner.isPrimaryConstructor) ""
212-
else "$" + funOwner.name + "$"
212+
else "$" + funOwner.unexpandedName + "$"
213213
)
214-
val oldClassPart = oldClass.name.decode
214+
val oldClassPart = oldClass.unexpandedName.decode
215215
// make sure the class name doesn't contain $anon, otherwise isAnonymousClass/Function may be true
216216
val name = unit.freshTypeName(s"$oldClassPart$suffix".replace("$anon", "$nestedInAnon"))
217217

test/files/pos/t9319.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Ydelambdafy:method

test/files/pos/t9319.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
object Test {
2+
3+
// was causing "filename too long" errors under -Ydelambdafy:method
4+
def main(args: Array[String]) {
5+
val x = List(1)
6+
(i: Int) => {
7+
(i: Int) => {
8+
(i: Int) => {
9+
(i: Int) => {
10+
(i: Int) => {
11+
(i: Int) => {
12+
(i: Int) => {
13+
(i: Int) => {
14+
(i: Int) => {
15+
()
16+
}
17+
18+
""
19+
}
20+
()
21+
}
22+
()
23+
}
24+
()
25+
}
26+
()
27+
}
28+
()
29+
}
30+
()
31+
}
32+
()
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)