scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Assertion failure in isAnonymousOrLocalClass #8900

Closed scabug closed 9 years ago

scabug commented 9 years ago

When using the 2.11.3 version that is currently on Maven Central or the most recent SNAPSHOT, I get an assertion failure when compiling the latest development version of our Kiama library. The build log is in the attached file, but the stack trace starts:

at scala.tools.nsc.backend.jvm.BCodeAsmCommon.isAnonymousOrLocalClass(BCodeAsmCommon.scala:35)
at scala.tools.nsc.backend.jvm.GenASM$JBuilder.scala$tools$nsc$backend$jvm$GenASM$JBuilder$$outerName$1(GenASM.scala:686)
at scala.tools.nsc.backend.jvm.GenASM$JBuilder.addInnerClasses(GenASM.scala:722)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1341)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.emitFor$1(GenASM.scala:197)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:203)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1338)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1325)
scabug commented 9 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8900?orig=1 Reporter: Tony Sloane (asloane) Affected Versions: 2.11.3 Attachments:

scabug commented 9 years ago

Tony Sloane (asloane) said: Forgot to say explicitly that the relevant version is the latest in this repo:

hg clone https://code.google.com/p/kiama/

The log mentions org.kiama.example.lambda2.LambdaTree so I presume the crash is triggered there somewhere, but I haven't narrowed it down yet.

scabug commented 9 years ago

Tony Sloane (asloane) said: The relevant commit seems to be

https://github.com/scala/scala/commit/63207e115a46634d47446a87a7f4bc3c2651b0e7

scabug commented 9 years ago

@retronym said: @lrytz We're getting a false positive from isDelambdafyFunction. The symbol name in question is LambdaTests$$anonfun$org$kiama$example$lambda2$LambdaTests$$canons$1$1. I don't have a smaller reproduction yet.

scabug commented 9 years ago

@gkossakowski said: Tony, can this issue be reproduced with released version of Kiama?

scabug commented 9 years ago

@Sciss said: Are the labels correct? It says affects 2.10.3 / fixed 2.10.4. Should it be 2.11.3?

scabug commented 9 years ago

@lrytz said: Hi @retronym, [~asloane]. The failing file is library/src/org/kiama/example/lambda2/LambdaTests.scala. As a reduced version, replace the content of the file by the follwing, it triggers the same error.

package org.kiama
package example.lambda2

import org.kiama.util.RegexParserTests
import scala.language.experimental.macros

class LambdaTests {
    import org.kiama.rewriting.Strategy
    def rule[T] (f : PartialFunction[T, T]) : Strategy = ???
    case class Var(x: Int)
    def canon = {
        def canons: Strategy = rule[Var] { case Var (n) => Var (n) } + canons
    }
}

The fishy thing is that Strategy.+ is a macro, and I could not reproduce the failure without the macro call. So it's possible that the assertion doesn't fail on compiler-generated code.

However, the implementation of isDelambdafyFunction (as well as isAnonymousFunction) is not robust at all against false positives:

    final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME)
    final def isDelambdafyFunction = isSynthetic && (name containsName tpnme.DELAMBDAFY_LAMBDA_CLASS_NAME)

So an assert(!sym.isDelambdafyFunction) is unsafe. I think for now we should just remove the assertion, longer term there should be a better implementation of the above.

scabug commented 9 years ago

@lrytz said: https://github.com/scala/scala/pull/4049

scabug commented 9 years ago

Tony Sloane (asloane) said: Grzegorz: yes, the same problem occurs with Kiama 1.7.0 which is the most recent release.

scabug commented 9 years ago

@gkossakowski said: Tony, would you be interested in adding Kiama 1.7.0 to the community build that we use to test Scala compiler? Given that you guys found a regression that none of 77 projects that are already there caught, it would be great to welcome you to the family!

scabug commented 9 years ago

Tony Sloane (asloane) said: Grzegorz, yes, no objections from me if you want to include Kiama in the community build. Is there anything I need to do?

scabug commented 9 years ago

@gkossakowski said: Tony, I was wondering if you could help with adding Kiama to community build. Adding a project to community build very often requires understanding of project's build so it's best done by project maintainers. Also, we are trying to spread the effort amongst community members so we can Scale the whole process to 100+ projects.

scabug commented 9 years ago

@sjrd said: This is also hit in Scala.js (see https://github.com/scala-js/scala-js/issues/1147).

In the case of Scala.js, I can tell you that it's not generated by a macro, because there's no macro in the Scala.js repository. The failing project is the test suite, which is not compiled with -Ydelambdafy:method. There is however, on the classpath of that compilation, another project which is compiled with -Ydelambdafy:method (the test-bridge).

scabug commented 9 years ago

Tony Sloane (asloane) said: Grzegorz, ok, I'll look into adding Kiama to the community build. Shouldn't be a problem.

scabug commented 9 years ago

Tony Sloane (asloane) said: Grzegorz, on the community build question, it appears that only git and svn are supported by dbuild at the moment. This limits what I can do since Kiama is in a Mercurial repository. I've added a ticket over at the dbuild tracker to flag this issue:

https://github.com/typesafehub/dbuild/issues/146.

scabug commented 9 years ago

@gkossakowski said (edited on Oct 20, 2014 12:50:21 PM UTC): Oh, it's a bummer we can't add Kiama to community build right away! Thanks for opening an issue against dbuild so we have that limitation documented. I hope dbuild can learn how to read Mercurial repos at some point.

Here's link to PR that fixes the original issue reported in this ticket: https://github.com/scala/scala/pull/4049