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

Assertion failed "class defined twice" with testCompilation #20296

Closed
aherlihy opened this issue Apr 30, 2024 · 4 comments · Fixed by #20815
Closed

Assertion failed "class defined twice" with testCompilation #20296

aherlihy opened this issue Apr 30, 2024 · 4 comments · Fixed by #20815

Comments

@aherlihy
Copy link
Contributor

aherlihy commented Apr 30, 2024

Compiler version

3.4.2-RC1

Minimized code

$sbt testCompilation tests/pos/shared-classname.scala. Does not fail with scalac tests/pos/shared-classname.scala.

(shortened version of not-looping-implicit.scala with the anonymous classes given the same name).

import scala.deriving.Mirror
import scala.compiletime._
trait Schema[T]
object Schema {
  inline given derived[A]: Schema[A] =
    inline summonInline[Mirror.Of[A]] match {
      case m: Mirror.SumOf[A] =>
        summonInline[Schema[m.MirroredElemTypes]]
        class InlinedSchema extends Schema[A] {}
        new InlinedSchema
      case m: Mirror.ProductOf[A] =>
        class InlinedSchema extends Schema[A] {}
        new InlinedSchema
    }
}
sealed trait InputValue
object InputValue {
  case class T() extends InputValue
}
@main def Test:Schema[InputValue] =
  Schema.derived

Output (click arrow to expand)

completed (0/1, 0 failed, 0s)java.lang.AssertionError: assertion failed: class defined twice class Schema$_$InlinedSchema 7130 6099
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.transform.TreeChecker.testDuplicate(TreeChecker.scala:55)
        ...
@aherlihy aherlihy added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 30, 2024
@nicolasstucki
Copy link
Contributor

Fails Ycheck after genSJSIR

checking t/Test.scala after phase MegaPhase{dropOuterAccessors, checkNoSuperThis, flatten, transformWildcards, moveStatic, expandPrivate, restoreScopes, selectStatic, Collect entry points, collectSuperCalls, repeatableAnnotations}
checking t/Test.scala after phase genSJSIR
java.lang.AssertionError: assertion failed: class defined twice class Schema$_$InlinedSchema 6090 7121
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.TreeChecker.testDuplicate(TreeChecker.scala:55)
        at dotty.tools.dotc.transform.TreeChecker.transformSym(TreeChecker.scala:78)
        at dotty.tools.dotc.core.DenotTransformers$SymTransformer.transform(DenotTransformers.scala:72)

@nicolasstucki
Copy link
Contributor

Minimization

trait Foo

object Foo {
  inline def bar(): Foo =
    class InlinedFoo extends Foo {}
    new InlinedFoo

  inline def foo(): Foo =
    bar()
    class InlinedFoo extends Foo {}
    new InlinedFoo

  def Test: Foo = Foo.foo()
}

@nicolasstucki
Copy link
Contributor

@sjrd could you check if this is an issue with genSJSIR or before that pahse?

@Gedochao Gedochao added area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 9, 2024
@sjrd
Copy link
Member

sjrd commented Jun 26, 2024

Something really weird is happening here. genSJSIR doesn't actually do anything, since -scalajs is not activated. However, its mere presence means that Ycheck gets to run twice between flatten and genBCode. It is the fact that Ycheck runs twice that somehow causes this class to be transformed twice, resulting in duplicates.

Moreover, -Ycheck:flatten alone does not cause the issue. -Ycheck:genSJSIR alone does not cause the issue. But the combined -Ycheck:flatten,genSJSIR does cause the issue!

Does that mean there's something side-effecting about Ycheck itself? Or that a previous transform side-effects while transforming symbols? It's all very strange, but in any case it's not about genSJSIR per se. We could replace it with a completely empty phase and the same issue would appear.

sjrd added a commit to dotty-staging/dotty that referenced this issue Jun 26, 2024
…alajs`.

This works around the issue seen in scala#20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled
build.
sjrd added a commit to dotty-staging/dotty that referenced this issue Jun 27, 2024
…alajs`.

This works around the issue seen in scala#20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled
build.
sjrd added a commit to dotty-staging/dotty that referenced this issue Jun 28, 2024
…alajs`.

This works around the issue seen in scala#20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled
build.
sjrd added a commit that referenced this issue Jun 28, 2024
…alajs`. (#20815)

This works around the issue seen in #20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled build.
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur added a commit that referenced this issue Jul 10, 2024
…alajs`.

This works around the issue seen in #20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled
build.

[Cherry-picked a88312b][modified]
WojciechMazur added a commit that referenced this issue Jul 10, 2024
…alajs`.

This works around the issue seen in #20296. However, the issue
resurfaces if we actually run `-Ycheck:all` in a Scala.js-enabled
build.

[Cherry-picked a88312b][modified]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants