Skip to content

Match type scrutinee is not dealiased (enough) #19821

Closed
@EugeneFlesselle

Description

@EugeneFlesselle

Compiler version

3.4.2-RC1

Minimized code

object Test:

  trait T:
    type S
    type F = T.F[S]

    def foo: F
    def bar: T.F[S]

  object T:
    type F[X] = X match
      case String => Option[Int]

    type G[X] = X match
      case Option[x] => Int

  val t: T {type S = String} = ???

  val b = t.bar
  val g: T.G[b.type] = ???
  val _: Int = g // Ok

  val f = t.foo
  val h: T.G[f.type] = ???
  val _: Int = h // Error

Output

-- [E007] Type Mismatch Error: tests/playground/example.scala:26:15 ------------
26 |  val _: Int = m // Error
   |               ^
   |               Found:    (Test.m : Test.T.G[(Test.f : Test.t.F)])
   |               Required: Int
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: Test.m
   | I tried to show that
   |   (Test.m : Test.T.G[(Test.f : Test.t.F)])
   | conforms to
   |   Int
   | but none of the attempts shown below succeeded:
   |
   |   ==> (Test.m : Test.T.G[(Test.f : Test.t.F)])  <:  Int
   |     ==> Test.T.G[(Test.f : Test.t.F)]  <:  Int
   |       ==> (Test.f : Test.t.F) match {   case Option[x] => Int }  <:  Int
   |         ==> Any  <:  Int  = false
   |
   | The tests were made under the empty constraint
    ----------------------------------------------------------------------------

Expectation

Should compile.
Or otherwise have the same behaviour with or without the F type alias.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions