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

Match type scrutinee is not dealiased (enough) #19821

Closed
EugeneFlesselle opened this issue Feb 28, 2024 · 0 comments · Fixed by #19871
Closed

Match type scrutinee is not dealiased (enough) #19821

EugeneFlesselle opened this issue Feb 28, 2024 · 0 comments · Fixed by #19871

Comments

@EugeneFlesselle
Copy link
Contributor

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.

@EugeneFlesselle EugeneFlesselle added itype:bug area:match-types stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2024
@dwijnand dwijnand removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Mar 1, 2024
@dwijnand dwijnand self-assigned this Mar 2, 2024
odersky added a commit that referenced this issue Apr 8, 2024
Proposes to make `isMatch` true only for `MatchType`s and higher-kinded
abstraction of them.

As a result, code using `isMatch` to choose between a `TypeAlias` and
`MatchAlias` will now use a `TypeAlias` when aliasing a `MatchAlias`.
Which in turn allows for better de-aliasing, since `dealias` only
de-aliases standard type aliases.

`tryNormalize` on `AppliedType` should only attempt reduction if there
is an underlying match type. This could previously be identified by a
`MatchAlias` tycon. We now need a recursive check.

Fixes #19821
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants