Skip to content

Mirror.SumOf contains more types than typer thinks are members of a sealed trait #22885

Open
@mrdziuban

Description

@mrdziuban

Compiler version

3.3.5, 3.6.4, and latest nightly 3.7.1-RC1-bin-20250325-701fa8a-NIGHTLY

Minimized code

import scala.deriving.Mirror

sealed trait DefinesType {
  sealed trait Type
  case object Foo extends Type
}
object ExtendsType1 extends DefinesType {
  case object Bar extends Type
}
object ExtendsType2 extends DefinesType {
  case object Baz extends Type
}

summon[Mirror.Of[ExtendsType1.Type]]

Output

scala.deriving.Mirror.Sum {
  type MirroredMonoType = ExtendsType1.Type
  type MirroredType = ExtendsType1.Type
  type MirroredLabel = "Type"
  type MirroredElemTypes = (ExtendsType1.Foo.type, ExtendsType1.Bar.type, ExtendsType2.Baz.type)
  type MirroredElemLabels = ("Foo", "Bar", "Baz")
}

Expectation

The Mirror for ExtendsType1.Type should not contain a reference to ExtendsType2.Baz since the Type that it extends (ExtendsType2.Type) is different. The typer believes this:

scala> ExtendsType2.Baz: ExtendsType1.Type
-- [E007] Type Mismatch Error: -------------------------------------------------
1 |ExtendsType2.Baz: ExtendsType1.Type
  |^^^^^^^^^^^^^^^^
  |Found:    ExtendsType2.Baz.type
  |Required: ExtendsType1.Type

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions