scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

java.lang.AssertionError: assertion failed: TS[753540, 753539, 753538] attempted to take ownership of B which is already owned by committable TS[808807, 753540, 753539, 753538]

Open rleibman opened this issue 1 year ago • 3 comments
trafficstars

Reproduction steps

Scala version: I'm able to reproduce it in both 3.4.2 and 3.5.0-RC1 (I was running with 3.5.0-RC1, but went back to 3.4.2 to see if it still happened there. It's a very complicated application, and everything was going fine, on my latest changes, I started getting this error.

To reproduce:

clone https://github.com/rleibman/dmscreen/tree/scalaError cd to the stLib directory and sbt publishLocal cd back to the root directory and sbt compile

Problem

[info]   exception occurred while typechecking /home/rleibman/projects/dmscreen/web/src/main/scala/dmscreen/dnd5e/EncounterPage.scala
[info] 
[info]   An unhandled exception was thrown in the compiler.
[info]   Please file a crash report here:
[info]   https://github.com/scala/scala3/issues/new/choose
[info]   For non-enriched exceptions, compile with -Yno-enrich-error-messages.
[info] 
[info]      while compiling: /home/rleibman/projects/dmscreen/web/src/main/scala/dmscreen/dnd5e/EncounterPage.scala
[info]         during phase: typer
[info]                 mode: Mode(ImplicitsEnabled)
[info]      library version: version 2.13.12
[info]     compiler version: version 3.4.2
[info]             settings: -Werror true -Xmax-inlines 128 -Yretain-trees true -classpath /home/rleibman/projects/dmscreen/web/target/scala-3.4.2/classes:/home/rleibman/projects/dmscreen/common/js/target/scala-3.4.2/classes:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_sjs1_3/3.4.2/scala3-library_sjs1_3-3.4.2.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-library_2.13/1.16.0/scalajs-library_2.13-1.16.0.jar:/home/rleibman/.ivy2/local/net.leibman/dmscreen-stlib_sjs1_3/0.3.0-SNAPSHOT/jars/dmscreen-stlib_sjs1_3.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/ghostdogpr/caliban-client_sjs1_3/2.7.2/caliban-client_sjs1_3-2.7.2.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio_sjs1_3/2.1.4/zio_sjs1_3-2.1.4.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/client3/core_sjs1_3/3.9.7/core_sjs1_3-3.9.7.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/scala-java-time_sjs1_3/2.6.0/scala-java-time_sjs1_3-2.6.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/scala-java-time-tzdb_sjs1_3/2.6.0/scala-java-time-tzdb_sjs1_3-2.6.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-dom_sjs1_3/2.8.0/scalajs-dom_sjs1_3-2.8.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/olvind/scalablytyped-runtime_sjs1_3/2.4.2/scalablytyped-runtime_sjs1_3-2.4.2.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/core_sjs1_3/2.1.1/core_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/extra_sjs1_3/2.1.1/extra_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/scalatags_sjs1_3/0.13.1/scalatags_sjs1_3-0.13.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalacss/core_sjs1_3/1.0.0/core_sjs1_3-1.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalacss/ext-react_sjs1_3/1.0.0/ext-react_sjs1_3-1.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-json_sjs1_3/0.7.0/zio-json_sjs1_3-0.7.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-prelude_sjs1_3/1.0.0-RC27/zio-prelude_sjs1_3-1.0.0-RC27.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/gnieh/diffson-core_sjs1_3/4.6.0/diffson-core_sjs1_3-4.6.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/megl/zio-json-extra_sjs1_3/0.6.2/zio-json-extra_sjs1_3-0.6.2.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/megl/zio-json-diffson_sjs1_3/0.6.2/zio-json-diffson_sjs1_3-0.6.2.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/kevinlee/just-semver-core_sjs1_3/0.13.0/just-semver-core_sjs1_3-0.13.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-core_sjs1_3/2.30.1/jsoniter-scala-core_sjs1_3-2.30.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-macros_sjs1_3/2.30.1/jsoniter-scala-macros_sjs1_3-2.30.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.13/scala-library-2.13.13.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-javalib/1.16.0/scalajs-javalib-1.16.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-scalalib_2.13/2.13.13%2B1.16.0/scalajs-scalalib_2.13-2.13.13%2B1.16.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/client3/jsoniter_sjs1_3/3.9.7/jsoniter_sjs1_3-3.9.7.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-core_3/2.30.1/jsoniter-scala-core_3-2.30.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-java-securerandom_sjs1_2.13/1.0.0/scalajs-java-securerandom_sjs1_2.13-1.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-internal-macros_sjs1_3/2.1.4/zio-internal-macros_sjs1_3-2.1.4.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-stacktracer_sjs1_3/2.1.4/zio-stacktracer_sjs1_3-2.1.4.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/izumi-reflect_sjs1_3/2.3.8/izumi-reflect_sjs1_3-2.3.8.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scala-js-macrotask-executor_sjs1_3/1.1.1/scala-js-macrotask-executor_sjs1_3-1.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-weakreferences_sjs1_2.13/1.0.0/scalajs-weakreferences_sjs1_2.13-1.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/model/core_sjs1_3/1.7.9/core_sjs1_3-1.7.9.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/shared/core_sjs1_3/1.3.16/core_sjs1_3-1.3.16.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/shared/ws_sjs1_3/1.3.16/ws_sjs1_3-1.3.16.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/portable-scala/portable-scala-reflect_sjs1_2.13/1.1.3/portable-scala-reflect_sjs1_2.13-1.1.3.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/scala-java-locales_sjs1_3/1.5.4/scala-java-locales_sjs1_3-1.5.4.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/callback_sjs1_3/2.1.1/callback_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/core-generic_sjs1_3/2.1.1/core-generic_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/util-fallbacks_sjs1_3/2.1.1/util-fallbacks_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/microlibs/compile-time_sjs1_3/4.0.0/compile-time_sjs1_3-4.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_sjs1_3/0.4.0/sourcecode_sjs1_3-0.4.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/geny_sjs1_3/1.1.0/geny_sjs1_3-1.1.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/univeq/univeq_sjs1_3/2.0.0/univeq_sjs1_3-2.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-streams_sjs1_3/2.1.1/zio-streams_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_sjs1_3/2.11.0/scala-collection-compat_sjs1_3-2.11.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/magnolia1_3/magnolia_sjs1_3/1.3.0/magnolia_sjs1_3-1.3.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-prelude-macros_sjs1_3/1.0.0-RC27/zio-prelude-macros_sjs1_3-1.0.0-RC27.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3/2.10.0/cats-core_sjs1_3-2.10.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/softwaremill/sttp/client3/json-common_sjs1_3/3.9.7/json-common_sjs1_3-3.9.7.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/izumi-reflect-thirdparty-boopickle-shaded_sjs1_3/2.3.8/izumi-reflect-thirdparty-boopickle-shaded_sjs1_3-2.3.8.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/cquiroz/cldr-api_sjs1_3/4.5.0/cldr-api_sjs1_3-4.5.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/util_sjs1_3/2.1.1/util_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/scalajs-react/facade_sjs1_3/2.1.1/facade_sjs1_3-2.1.1.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/japgolly/microlibs/types_sjs1_3/4.0.0/types_sjs1_3-4.0.0.jar:/home/rleibman/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_sjs1_3/2.10.0/cats-kernel_sjs1_3-2.10.0.jar -d /home/rleibman/projects/dmscreen/web/target/scala-3.4.2/classes -deprecation true -encoding utf-8 -feature true -language List(existentials, implicitConversions, higherKinds) -no-indent true -old-syntax true -scalajs true
[error] ## Exception when compiling 42 sources to /home/rleibman/projects/dmscreen/web/target/scala-3.4.2/classes
[error] java.lang.AssertionError: assertion failed: TS[753540, 753539, 753538] attempted to take ownership of B which is already owned by committable TS[808807, 753540, 753539, 753538]
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.core.TyperState.includeVar(TyperState.scala:272)
[error] dotty.tools.dotc.core.TyperState.$anonfun$2$$anonfun$1(TyperState.scala:234)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.core.TyperState.$anonfun$2(TyperState.scala:234)

rleibman avatar Jun 24 '24 03:06 rleibman

Also, for what it's worth, the error happened when in the diff from the main branch to the scalaError branch.

rleibman avatar Jun 24 '24 04:06 rleibman

We'll need to minimise this. It seems to me there's a lot of extra code in the repo, + a lot of dependencies, SBT plugins, etc. Optimally, we'll need a minimised example with no dependencies.

@rleibman can you help?

Gedochao avatar Jun 25 '24 07:06 Gedochao

Yeah, I know, unfortunately I don't have a lot of time to reproduce a minimal version, at least I know that it happens on that specific branch, so there's only a few files that are affected. I believe it's in one of the scala.js files, for what it's worth. I'm sorry if I can't be more specific and don't have much time to spend on it. I removed most of those changes from my main branch and can keep on working for now. BTW, I understand if this is not enough to go on and you guys can't work on it, though there's always bugs that only show up in "real" code. Based on the error message, is there any ideas about what it could be?

rleibman avatar Jun 25 '24 18:06 rleibman

@Gedochao I'm seeing the same problem (with different integer values in the assertion failure).

I've managed to minimize the reproduction down to what I think is small enough to think about debugging the failure.

Given there are already several duplicates of this issue, may I simply leave steps to reproduce in this ticket, as it seems to be the first one? I'll add a following comment...

sageserpent-open avatar Oct 22 '24 13:10 sageserpent-open

**Reproduction: **

The repository: https://github.com/sageserpent-open/kineticMerge at commit: af774510ad44a859bd28ca6b7a6549677fea9507 (branch: dotty-typer-assertion-failure-reproduction) contains the minimized source code and build.sbt.

Scala build uses 3.3.4.

Code follows inline:

  1. build.sbt
import scala.language.postfixOps

lazy val javaVersion = "17"

ThisBuild / scalaVersion := "3.3.4"

ThisBuild / javacOptions ++= Seq("-source", javaVersion, "-target", javaVersion)

ThisBuild / scalacOptions += s"-java-output-version:$javaVersion"

lazy val root = (project in file("."))
  .settings(
    scalacOptions ++= List("-source:future"),
    name                                   := "kinetic-merge",
    libraryDependencies += "org.typelevel" %% "cats-core" % "2.12.0"
  )
  1. Bystander.scala
package com.sageserpent.kineticmerge.core

import cats.Eval
import cats.data.StateT

case class Bystander():
end Bystander

object Bystander:
  type PartialResultsCache = Unit

  type EvalWithPartialResultState[X] = StateT[Eval, PartialResultsCache, X]

  def of(
      index: Int
  ): EvalWithPartialResultState[Bystander] =
    StateT.get.flatMap { partialResultsCache =>
      _of(index)
        .flatMap(computedResult =>
          StateT
            .set(???)
          // This last call to `>>` with the rhs operand triggers the assertion
          // failure. Commenting it out yields an expected compilation error...
            >> StateT.pure(
              computedResult
            )
        )
    }
  end of

  def _of(
      index: Int
  ): EvalWithPartialResultState[Bystander] = ???
end Bystander

Error message from SBT:

(Compile / compileIncremental) java.lang.AssertionError: assertion failed: TS[3038, 3037, 3036] attempted to take ownership of B which is already owned by committable TS[3570, 3038, 3037, 3036]

Stack trace when building via IntelliJ:

scala: ## Exception when compiling 1 sources to /Users/gerardmurphy/IdeaProjects/kineticMerge/target/scala-3.3.4/classes
java.lang.AssertionError: assertion failed: TS[572497715, 572497714, 572497713] attempted to take ownership of B which is already owned by committable TS[572498247, 572497715, 572497714, 572497713]
scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
dotty.tools.dotc.core.TyperState.includeVar(TyperState.scala:271)
dotty.tools.dotc.core.TyperState.$anonfun$2$$anonfun$1(TyperState.scala:233)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.collection.immutable.List.foreach(List.scala:334)
dotty.tools.dotc.core.TyperState.$anonfun$2(TyperState.scala:232)
scala.collection.immutable.List.forall(List.scala:387)
dotty.tools.dotc.core.TyperState.mergeConstraintWith(TyperState.scala:227)
dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArgs(ProtoTypes.scala:483)
dotty.tools.dotc.typer.ProtoTypes$FunProto.fold(ProtoTypes.scala:569)
dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6366)
dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6404)
dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:641)
dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6403)
dotty.tools.dotc.core.Types$TypeTraverser.apply(Types.scala:6403)
dotty.tools.dotc.typer.ProtoTypes$SelectionProto.fold(ProtoTypes.scala:245)
dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:6366)
dotty.tools.dotc.core.Types$TypeTraverser.traverseChildren(Types.scala:6404)

...

sageserpent-open avatar Oct 22 '24 13:10 sageserpent-open

I should add that changing the offending >> StateT.pure(computedResult) to the more pedestrian .flatMap(_ => StateT.pure(computedResult)) avoids the bug altogether.

For that matter, remembering to put in import cats.syntax.flatMap.* doesn't help avoid the fault, I thought this might have been down to the built-in >> being consulted.

sageserpent-open avatar Oct 22 '24 13:10 sageserpent-open

Removed the commit for reproduction from the Kinetic Merge repository, as apparently this is a duplicate of #23663; that has been closed.

sageserpent-open avatar Oct 27 '25 13:10 sageserpent-open