Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some methods with lambda in the name will crash the compiler #12015

Closed
snoble opened this issue May 23, 2020 · 2 comments
Closed

Some methods with lambda in the name will crash the compiler #12015

snoble opened this issue May 23, 2020 · 2 comments

Comments

@snoble
Copy link

snoble commented May 23, 2020

reproduction steps

repo with sbt build: https://github.com/snoble/scala-crash

scastie link: https://scastie.scala-lang.org/MywoibUzRSm0Sfb7jGjK8w

using Scala (2.13.1) (reproduced in 2.13.2 and 2.12.11),

Welcome to Scala 2.13.1 (OpenJDK 64-Bit Server VM, Java 1.8.0_252).
Type in expressions for evaluation. Or try :help.

scala> object Crash {
     |   def lambdaList(lst: List[Int]): List[Int] = lst.collect { case n if n > 0 => n }
     | }
error: Error while emitting <console>
assertion failed:
  $read$Crash$$anonfun$lambdaList$1
     while compiling: <console>
        during phase: jvm
     library version: version 2.13.1
    compiler version: version 2.13.1
  reconstructed args: -deprecation -feature

  last tree to typer: Ident(default)
       tree position: line 2 of <console>
            tree tpe: Function1
              symbol: value default
   symbol definition: default: Function1 (a TermSymbol)
      symbol package: $line3
       symbol owners: value default -> method applyOrElse -> <$anon: Function1>
           call site: constructor $read$Crash$$anonfun$lambdaList$1 in package $line3

== Source file context for tree position ==

     1 object Crash {
     2   def lambdaList(lst: List[Int]): List[Int] = lst.collect { case n if n > 0 => n }
     3 }
     4
error: Error while emitting Crash$
assertion failed: $read$Crash$$anonfun$lambdaList$1

problem

it shouldn't error when emitting. Somehow the combination of calling collect and a def that starts with lambda is necessary.

@som-snytt
Copy link

It's funnier if you call the method lambdaLift.

➜ ✗ scala -Vdebug
scala> def lambdaList(lst: List[Int]): List[Int] = lst.collect { case n if n > 0 => n }
java.lang.AssertionError: assertion failed: $read$$iw$$anonfun$lambdaList$1
at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)
at scala.tools.nsc.backend.jvm.BCodeHelpers.isAnonymousOrLocalClass(BCodeHelpers.scala:86)

where the code comment is

// if some outer name contains $lambda, a non-lambda class is considered lambda.

@som-snytt
Copy link

Duplicates #10857 and #2806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants