summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-10-12 21:49:04 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-10-15 08:21:02 +0200
commit347f01d46408d2430be3aea0184f5a6b8d9bbe81 (patch)
tree57769221008ef76b1036da403b78fd2c6fab18aa
parent2b5df373638d08204b71258928289f6b39e25d5f (diff)
downloadscala-347f01d46408d2430be3aea0184f5a6b8d9bbe81.tar.gz
scala-347f01d46408d2430be3aea0184f5a6b8d9bbe81.tar.bz2
scala-347f01d46408d2430be3aea0184f5a6b8d9bbe81.zip
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!
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala8
-rw-r--r--test/files/pos/t8900.scala11
2 files changed, 15 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
index 4285858bf8..14b61777b0 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala
@@ -30,10 +30,10 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
*/
def isAnonymousOrLocalClass(classSym: Symbol): Boolean = {
assert(classSym.isClass, s"not a class: $classSym")
- val res = (classSym.isAnonymousClass || !classSym.originalOwner.isClass)
- // lambda classes are always top-level classes.
- if (res) assert(!classSym.isDelambdafyFunction)
- res
+ // Here used to be an `assert(!classSym.isDelambdafyFunction)`: delambdafy lambda classes are
+ // always top-level. However, SI-8900 shows an example where the weak name-based implementation
+ // of isDelambdafyFunction failed (for a function declared in a package named "lambda").
+ classSym.isAnonymousClass || !classSym.originalOwner.isClass
}
/**
diff --git a/test/files/pos/t8900.scala b/test/files/pos/t8900.scala
new file mode 100644
index 0000000000..376bd786f2
--- /dev/null
+++ b/test/files/pos/t8900.scala
@@ -0,0 +1,11 @@
+package foo
+package lambdaking
+
+class Test {
+ def byname(b: => Any) = ???
+ def foo: Any = {
+ def bar: Any = {
+ byname(bar)
+ }
+ }
+}