question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler crash when a `given` instance of a trait with inline defs is not inline

See original GitHub issue

Compiler version

3.0.0

Minimized code


trait Noop[T]:
  inline def noop(fa: T): T

final case class User(name: String, age: Int)

given Noop[User] = a => a

Output (click arrow to expand)

sbt:scala3-live> compile
[info] compiling 1 Scala source to /Users/jkoslowski/dev/scala3-live/target/scala-3.0.0/classes ...
exception while typing closure($anonfun:com.example.Noop[com.example.User]) of class class dotty.tools.dotc.ast.Trees$Closure # -1
exception while typing {
  def $anonfun(a: com.example.User): com.example.User = a
  closure($anonfun:com.example.Noop[com.example.User])
} of class class dotty.tools.dotc.ast.Trees$Block # -1
exception while typing final lazy given def given_Noop_User: com.example.Noop[com.example.User] = 
  {
    def $anonfun(a: com.example.User): com.example.User = a
    closure($anonfun:com.example.Noop[com.example.User])
  } of class class dotty.tools.dotc.ast.Trees$DefDef # -1
exception while typing @scala.annotation.internal.SourceFile(
  "src/main/scala/com/example/Examples.scala"
) final module class Examples$package$() extends Object() {
  private def writeReplace(): AnyRef = 
    new scala.runtime.ModuleSerializationProxy(
      classOf[com.example.Examples$package.type]
    )
  final lazy given def given_Noop_User: com.example.Noop[com.example.User] = 
    {
      def $anonfun(a: com.example.User): com.example.User = a
      closure($anonfun:com.example.Noop[com.example.User])
    }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # -1
exception while typing package com.example {
  @scala.annotation.internal.SourceFile(
    "src/main/scala/com/example/Examples.scala"
  ) trait Noop[T]() extends Object {
    private type T
    private inline def noop(fa: T): T
  }
  @scala.annotation.internal.SourceFile(
    "src/main/scala/com/example/Examples.scala"
  ) final case class User(name: String, age: Int) extends Object(), Product, 
    Serializable
   {
    override def hashCode(): Int = 
      {
        var acc: Int = -889275714
        acc = scala.runtime.Statics$#mix(acc, this.productPrefix.hashCode())
        acc = 
          scala.runtime.Statics$#mix(acc, 
            scala.runtime.Statics$#anyHash(User.this.name)
          )
        acc = scala.runtime.Statics$#mix(acc, User.this.age)
        scala.runtime.Statics$#finalizeHash(acc, 2)
      }
    override def equals(x$0: Any): Boolean = 
      this.eq(x$0.$asInstanceOf$[Object]).||(
        matchResult1[Boolean]: 
          {
            case val x1: (x$0 : Object) = x$0
            if x1.$isInstanceOf$[com.example.User @unchecked] then 
              {
                case val x$0: com.example.User = 
                  x1.$asInstanceOf$[com.example.User @unchecked]
                return[matchResult1] 
                  this.age.==(x$0.age).&&(this.name.==(x$0.name))
              }
             else ()
            return[matchResult1] false
          }
      )
    override def toString(): String = scala.runtime.ScalaRunTime._toString(this)
    override def canEqual(that: Any): Boolean = 
      that.isInstanceOf[com.example.User @unchecked]
    override def productArity: Int = 2
    override def productPrefix: String = "User"
    override def productElement(n: Int): Any = 
      matchResult2[Object]: 
        {
          case val x3: (n : Int) = n
          if 0.==(x3) then return[matchResult2] this._1 else ()
          if 1.==(x3) then return[matchResult2] this._2 else ()
          throw new IndexOutOfBoundsException(n.toString())
        }
    override def productElementName(n: Int): String = 
      matchResult3[String]: 
        {
          case val x4: (n : Int) = n
          if 0.==(x4) then return[matchResult3] "name" else ()
          if 1.==(x4) then return[matchResult3] "age" else ()
          throw new IndexOutOfBoundsException(n.toString())
        }
    def name: String
    def age: Int
    def copy(name: String, age: Int): com.example.User = 
      new com.example.User(name, age)
    def copy$default$1: String @uncheckedVariance = User.this.name
    def copy$default$2: Int @uncheckedVariance = User.this.age
    def _1: String = this.name
    def _2: Int = this.age
  }
  final lazy module val User: com.example.User$ = new com.example.User$()
  @scala.annotation.internal.SourceFile(
    "src/main/scala/com/example/Examples.scala"
  ) final module class User$() extends AnyRef(), scala.deriving.Mirror.Product {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(classOf[com.example.User.type])
    def apply(name: String, age: Int): com.example.User = 
      new com.example.User(name, age)
    def unapply(x$1: com.example.User): com.example.User = x$1
    override def toString: String = "User"
    type MirroredMonoType = com.example.User
    def fromProduct(x$0: Product): com.example.User.MirroredMonoType = 
      new com.example.User(x$0.productElement(0).$asInstanceOf$[String], 
        x$0.productElement(1).$asInstanceOf$[Int]
      )
  }
  final lazy module val Examples$package: com.example.Examples$package$ = 
    new com.example.Examples$package$()
  @scala.annotation.internal.SourceFile(
    "src/main/scala/com/example/Examples.scala"
  ) final module class Examples$package$() extends Object() {
    private def writeReplace(): AnyRef = 
      new scala.runtime.ModuleSerializationProxy(
        classOf[com.example.Examples$package.type]
      )
    final lazy given def given_Noop_User: com.example.Noop[com.example.User] = 
      {
        def $anonfun(a: com.example.User): com.example.User = a
        closure($anonfun:com.example.Noop[com.example.User])
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # -1
[info] exception occurred while compiling /Users/jkoslowski/dev/scala3-live/src/main/scala/com/example/Examples.scala
scala.MatchError: List() (of class scala.collection.immutable.Nil$) while compiling /Users/jkoslowski/dev/scala3-live/src/main/scala/com/example/Examples.scala
[error] ## Exception when compiling 1 sources to /Users/jkoslowski/dev/scala3-live/target/scala-3.0.0/classes
[error] scala.MatchError: List() (of class scala.collection.immutable.Nil$)
[error] dotty.tools.dotc.transform.Erasure$Boxing$.adaptClosure(Erasure.scala:436)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClosure(Erasure.scala:1032)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2680)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2731)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2796)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2800)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2916)
[error] dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1018)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2677)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2731)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2796)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2800)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2916)
[error] dotty.tools.dotc.typer.Typer.$anonfun$34(Typer.scala:2142)
[error] dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
[error] dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2142)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:955)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2646)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2730)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2796)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2800)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2822)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2872)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1068)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2328)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1057)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2657)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2661)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2730)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2796)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2800)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2822)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2872)
[error] dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1068)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2451)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2702)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2731)
[error] dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:118)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2796)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:2800)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2916)
[error] dotty.tools.dotc.transform.Erasure.run(Erasure.scala:132)
[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:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
[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:457)
[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:412)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:499)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:399)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:166)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
[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:2346)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2303)
[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:2299)
[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.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] java.base/java.lang.Thread.run(Thread.java:834)
[error]            
[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) scala.MatchError: List() (of class scala.collection.immutable.Nil$)
[error] Total time: 0 s, completed 21 May 2021, 16:09:51

Related: #12555

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
LPTKcommented, May 27, 2021

As we only provide given Noop[User] we will never be able to devirtualize the call at compile-time

Note that it works with given Noop[User] with ... (as in my message above).

0reactions
oderskycommented, Apr 7, 2022

I guess classes with only abstract inline defs should not be SAM types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transparent inline method call doesn't expand inside another inline ...
Compiler version 3.0.0 Minimized code First sample transparent inline def ... Calls are never inlined in inline methods, so this does not work....
Read more >
The usage of the inlining of given instances in Scala 3
The inlining of given instances will not inline/duplicate the implementation of the given, it will just inline the instantiation of that ...
Read more >
lampepfl/dotty - Gitter
sealed trait HList case object HNil extends HList case class HCons[+H, +T <: HList](h: H, t: T) extends HList inline def concat(xs: HList, ......
Read more >
Issues related to possible `HasThisType` implementation in Scala ...
I have some filling that nice and proper HasThisType -trait ... makes Dotty compiler infinitely hang (or crash), while Scala compiler could not...
Read more >
inline - ModernesCpp.com
ODR stands for the One Definition Rule and says in the case of a function. ... In modern compilers, the keyword inline is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found