Skip to content

Commit 347f01d

Browse files
committed
SI-8900 Don't assert !isDelambdafyFunction, it may not be accurate
The implementations of isAnonymousClass, isAnonymousFunction, isDelambdafyFunction and isDefaultGetter check if a specific substring (eg "$lambda") exists in the symbol's name. SI-8900 shows an example where a class ends up with "$lambda" in its name even though it's not a delambdafy lambda class. In this case the conflict seems to be introduced by a macro. It is possible that the compiler itself never introduces such names, but in any case, the above methods should be implemented more robustly. This commit is band-aid, it fixes one specific known issue, but there are many calls to the mentioned methods across the compiler which are potentially wrong. Thanks to Jason for the test case!
1 parent 2b5df37 commit 347f01d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
3030
*/
3131
def isAnonymousOrLocalClass(classSym: Symbol): Boolean = {
3232
assert(classSym.isClass, s"not a class: $classSym")
33-
val res = (classSym.isAnonymousClass || !classSym.originalOwner.isClass)
34-
// lambda classes are always top-level classes.
35-
if (res) assert(!classSym.isDelambdafyFunction)
36-
res
33+
// Here used to be an `assert(!classSym.isDelambdafyFunction)`: delambdafy lambda classes are
34+
// always top-level. However, SI-8900 shows an example where the weak name-based implementation
35+
// of isDelambdafyFunction failed (for a function declared in a package named "lambda").
36+
classSym.isAnonymousClass || !classSym.originalOwner.isClass
3737
}
3838

3939
/**

test/files/pos/t8900.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package foo
2+
package lambdaking
3+
4+
class Test {
5+
def byname(b: => Any) = ???
6+
def foo: Any = {
7+
def bar: Any = {
8+
byname(bar)
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)