Skip to content

compiler throw AssertionError when use singleton type "isEmpty" extractor #11605

Closed
@xuwei-k

Description

@xuwei-k

Compiler version

3.0.0-RC1 and 3.0.0-RC2-bin-20210303-0be4099-NIGHTLY

Minimized code

package example

class Extractor[A](val get: A) extends AnyVal {
  // https://github.com/scala/scala/pull/9343
  def isEmpty: false = false
}

object Foo {
  def unapply(x: String): Extractor[String] = new Extractor(x)
}

object Main {
  val Foo(a) = "a"
}

Output (click arrow to expand)

exception while typing example.Extractor.isEmpty$extension[String](x4).unary_! of class class dotty.tools.dotc.ast.Trees$Select # -1
exception while typing if example.Extractor.isEmpty$extension[String](x4).unary_! then 
  {
    case val a: String = x4.get
    return[matchResult2] a:String
  }
 else () of class class dotty.tools.dotc.ast.Trees$If # -1
exception while typing {
  case val x4: example.Extractor[String] = example.Foo.unapply(x3)
  if example.Extractor.isEmpty$extension[String](x4).unary_! then 
    {
      case val a: String = x4.get
      return[matchResult2] a:String
    }
   else ()
} of class class dotty.tools.dotc.ast.Trees$Block # -1
exception while typing if x3.ne(null) then 
  {
    case val x4: example.Extractor[String] = example.Foo.unapply(x3)
    if example.Extractor.isEmpty$extension[String](x4).unary_! then 
      {
        case val a: String = x4.get
        return[matchResult2] a:String
      }
     else ()
  }
 else () of class class dotty.tools.dotc.ast.Trees$If # -1
exception while typing {
  case val x3: String @unchecked = "a":String @unchecked
  if x3.ne(null) then 
    {
      case val x4: example.Extractor[String] = example.Foo.unapply(x3)
      if example.Extractor.isEmpty$extension[String](x4).unary_! then 
        {
          case val a: String = x4.get
          return[matchResult2] a:String
        }
       else ()
    }
   else ()
  throw new MatchError(x3)
} of class class dotty.tools.dotc.ast.Trees$Block # -1
exception while typing matchResult2[String]: 
  {
    case val x3: String @unchecked = "a":String @unchecked
    if x3.ne(null) then 
      {
        case val x4: example.Extractor[String] = example.Foo.unapply(x3)
        if example.Extractor.isEmpty$extension[String](x4).unary_! then 
          {
            case val a: String = x4.get
            return[matchResult2] a:String
          }
         else ()
      }
     else ()
    throw new MatchError(x3)
  } of class class dotty.tools.dotc.ast.Trees$Labeled # -1
exception while typing def a: String = 
  matchResult2[String]: 
    {
      case val x3: String @unchecked = "a":String @unchecked
      if x3.ne(null) then 
        {
          case val x4: example.Extractor[String] = example.Foo.unapply(x3)
          if example.Extractor.isEmpty$extension[String](x4).unary_! then 
            {
              case val a: String = x4.get
              return[matchResult2] a:String
            }
           else ()
        }
       else ()
      throw new MatchError(x3)
    } of class class dotty.tools.dotc.ast.Trees$DefDef # -1
exception while typing @scala.annotation.internal.SourceFile("A.scala") final module class Main$()
   extends
 Object() {
  private def writeReplace(): AnyRef = 
    new scala.runtime.ModuleSerializationProxy(classOf[example.Main.type])
  def a: String = 
    matchResult2[String]: 
      {
        case val x3: String @unchecked = "a":String @unchecked
        if x3.ne(null) then 
          {
            case val x4: example.Extractor[String] = example.Foo.unapply(x3)
            if example.Extractor.isEmpty$extension[String](x4).unary_! then 
              {
                case val a: String = x4.get
                return[matchResult2] a:String
              }
             else ()
          }
         else ()
        throw new MatchError(x3)
      }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # -1
exception while typing package example {
  @scala.annotation.internal.SourceFile("A.scala") final class Extractor[A](
    get: A
  ) extends AnyVal() {
    override def hashCode(): Int = 
      example.Extractor.hashCode$extension[A](this)()
    override def equals(x$0: Any): Boolean = 
      example.Extractor.equals$extension[A](this)(x$0)
    private type A
    def get: A
    def isEmpty: (false : Boolean) = 
      example.Extractor.isEmpty$extension[A](this)
  }
  final lazy module val Extractor: example.Extractor$ = new example.Extractor$()
  @scala.annotation.internal.SourceFile("A.scala") final module class Extractor$
    ()
   extends AnyRef() {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(classOf[example.Extractor.type]
        )
    final def hashCode$extension[A]($this: example.Extractor[A])(): Int = 
      $this.get.hashCode()
    final def equals$extension[A]($this: example.Extractor[A])(x$0: Any): 
      Boolean
     = 
      matchResult1[Boolean]: 
        {
          case val x1: (x$0 : Object) = x$0
          if x1.$isInstanceOf$[example.Extractor[A] @unchecked] then 
            {
              case val x$0: example.Extractor[A] = 
                x1.$asInstanceOf$[example.Extractor[A] @unchecked]
              return[matchResult1] $this.get.==(x$0.get)
            }
           else ()
          return[matchResult1] false
        }
    final def isEmpty$extension[A]($this: example.Extractor[A]): 
      (false : Boolean)
     = false
  }
  final lazy module val Foo: example.Foo$ = new example.Foo$()
  @scala.annotation.internal.SourceFile("A.scala") final module class Foo$()
     extends
   Object() {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(classOf[example.Foo.type])
    def unapply(x: String): example.Extractor[String] = 
      new example.Extractor[String](x)
  }
  final lazy module val Main: example.Main$ = new example.Main$()
  @scala.annotation.internal.SourceFile("A.scala") final module class Main$()
     extends
   Object() {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(classOf[example.Main.type])
    def a: String = 
      matchResult2[String]: 
        {
          case val x3: String @unchecked = "a":String @unchecked
          if x3.ne(null) then 
            {
              case val x4: example.Extractor[String] = example.Foo.unapply(x3)
              if example.Extractor.isEmpty$extension[String](x4).unary_! then 
                {
                  case val a: String = x4.get
                  return[matchResult2] a:String
                }
               else ()
            }
           else ()
          throw new MatchError(x3)
        }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # -1
[info] exception occurred while compiling /Users/kenji/isEmpty-value-class-scala-3/A.scala
java.lang.AssertionError: assertion failed:  <none> while compiling /Users/kenji/isEmpty-value-class-scala-3/A.scala
[error] ## Exception when compiling 1 sources to /Users/kenji/isEmpty-value-class-scala-3/target/scala-3.0.0-RC2/classes
[error] java.lang.AssertionError: assertion failed:  <none>
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:687)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2580)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2671)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.typedIf(Typer.scala:1041)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedIf(Erasure.scala:850)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2619)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2672)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2857)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:993)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2618)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2672)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.$anonfun$11(Typer.scala:1050)
[error] dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:2124)
[error] dotty.tools.dotc.typer.Applications.harmonic$(Applications.scala:303)
[error] dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:102)
[error] dotty.tools.dotc.typer.Typer.typedIf(Typer.scala:1053)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedIf(Erasure.scala:850)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2619)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2672)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2790)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2813)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1026)
[error] dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:987)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:991)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2618)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2672)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.typedLabeled(Typer.scala:1575)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2603)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2671)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2857)
[error] dotty.tools.dotc.typer.Typer.$anonfun$35(Typer.scala:2097)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2097)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:918)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2587)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2671)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2763)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2813)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1026)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2243)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1015)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2598)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2602)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2671)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2763)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2813)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1026)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2395)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2643)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2672)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2737)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2741)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2857)
[error] dotty.tools.dotc.transform.Erasure.run(Erasure.scala:125)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:303)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:304)
[error] dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:205)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$5(Run.scala:215)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:223)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:230)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:166)
[error] dotty.tools.dotc.Run.compile(Run.scala:150)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:186)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:241)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:176)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:157)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:204)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:587)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:587)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:174)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:172)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:261)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:166)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:587)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:491)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2301)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2258)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2254)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:748)
[error]            
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed:  <none>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions