Skip to content

Changed type constraint behaviour when pattern matching with unions #22882

Open
@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failure in in outr/lightdb

Compiler version

Last good release: 3.7.1-RC1-bin-20250323-451fdcd-NIGHTLY
First bad release: 3.7.1-RC1-bin-20250325-701fa8a-NIGHTLY

Bisect points to either 451fdcd or 701fa8a (most likekly)

Minimized code

trait Document[Doc <: Document[Doc]]
sealed trait Conversion[Doc, V]

object Conversion {
  case class Doc[Doc <: Document[Doc]]() extends Conversion[Doc, Doc]
  case class Converted[Doc <: Document[Doc], T](f: Doc => T) extends Conversion[Doc, T]
}

def Test[Doc <: Document[Doc], V](conversion: Conversion[Doc, V]) = 
  val fails = conversion match 
    case Conversion.Doc() | Conversion.Converted(_) => ??? // error
  val works = conversion match 
    case Conversion.Doc() => ???
    case Conversion.Converted(_) => ???

Output

-- [E057] Type Mismatch Error: /Users/wmazur/projects/scala/sandbox/test.scala:12:9 ---------------------------------------------------------------------------------------------------------
12 |    case Conversion.Doc() | Conversion.Converted(_) => ??? // error
   |         ^
   |         Type argument V does not conform to upper bound Document[V]
   |
   | longer explanation available when compiling with `-explain`

Expectation

Should probably compile without error or fail in both cases

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions