scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

Multi-module match type regression in 3.3.2 #18261

Open soronpo opened 1 year ago

soronpo commented 1 year ago

This compilation error requires multi-module and multi-file to trigger.

Compiler version

Last good release: 3.3.2-RC1-bin-20230630-c629090-NIGHTLY First bad release: 3.3.2-RC1-bin-20230703-0a21ecf-NIGHTLY

Minimized code

See minimized project at: https://github.com/soronpo/dottybug/tree/matchtypebug

main/DFBits.scala

trait DFBits[W <: Int]

trait Candidate[R]:
  type OutW <: Int
object Candidate:
  given [W <: Int, R <: Foo[DFBits[W]]]: Candidate[R] with
    type OutW = W

main/Foo.scala

type Foo[T] = T match
  case Any => T

test/Test.scala

def baz[L](lhs: L)(using icL: Candidate[L]): DFBits[Int] = ???
object Test:
  val x: DFBits[8] = ???
  val z: DFBits[Int] = baz(x)
  summon[Candidate[z.type]]

Output

[error] 5 |  summon[Candidate[z.type]]
[error]   |                           ^
[error]   |No given instance of type Candidate[(Test.z : DFBits[Int])] was found for parameter x of method summon in object Predef.
[error]   |I found:
[error]   |
[error]   |    Candidate.given_Candidate_R[W, R]
[error]   |
[error]   |But given instance given_Candidate_R in object Candidate does not match type Candidate[(Test.z : DFBits[Int])].

Expectation

No error.

soronpo commented 1 year ago

First bad commit: 8aec1d11abc94f8695973380f7b740f4b76574bb

soronpo commented 1 year ago

A minor change to the minimized example causes the issue to resurface. Here is the update minimized example (also pushed the update to https://github.com/soronpo/dottybug/tree/matchtypebug):

main/DFBits.scala

trait DFBits[W <: Int]

trait Candidate[R]:
  type OutW <: Int
object Candidate:
  given [W <: Int, R <: Foo[DFBits[W], VAL]]: Candidate[R] with
    type OutW = W

main/Foo.scala

trait VAL

type Foo[T, M] = M match
  case VAL => T

test/Test.scala

def baz[L](lhs: L)(using icL: Candidate[L]): DFBits[Int] = ???
object Test:
  val x: DFBits[8] = ???
  val z: DFBits[Int] = baz(x)
  summon[Candidate[z.type]]
EugeneFlesselle commented 5 months ago

Fixing this issue depends on #20168, #20258, #20205, #20259, #20184, #20178, #20268

soronpo commented 5 months ago

Fixing this issue depends on #20168, #20258, #20205, #20259 #20184, #20178

😮