Skip to content

Compiler crash: assertion failed during "superaccessors" stage. #9707

@scabug

Description

@scabug
object Crash {
   implicit class Chain[T](val wrapped:T) extends AnyVal {
      def andThen[P,R](f: P => R)(implicit ev: T <:< (() => P)): R =
        f(ev(wrapped).apply)
   }

   class Foo {
      var x = 0
      def getX = x
   }

   def main(args: Seq[String]) {
      val result = new Foo {
        override def getX = {  x += 1 } andThen { _: Unit => x }
      }
      println(result)
   }
}

Compiling this causes compiler to crash:

Exception in thread "main" java.lang.AssertionError: assertion failed: 
  x.<$plus$eq: error>(1)
     while compiling: Crash.scala
        during phase: superaccessors
     library version: version 2.11.7
    compiler version: version 2.11.7
  reconstructed args: 

  last tree to typer: Ident(x)
       tree position: line 2 of Crash.scala
            tree tpe: Boolean
              symbol: value x
   symbol definition: x: Boolean (a TermSymbol)
      symbol package: <none>
       symbol owners: value x
           call site: method getX in package <empty>

== Source file context for tree position ==

     0 object Crash {
     1    implicit class Chain[T](val wrapped:T) extends AnyVal {
     2       def andThen[P,R](f: P => R)(implicit ev: T <:< (() => P)): R =
     3         f(ev(wrapped).apply)
     4    }
     5 
     6    class Foo {
	at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:358)
	at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:71)
	at scala.reflect.internal.Trees$class.itransform(Trees.scala:1345)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)

I understand, that this code is really messed up in more ways than one ... Still would be nice to get a more or less descriptive explanation of what I've done wrong rather than crashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendcompiler crashfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions