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

Regression in GADT type inference inside polymorphic function #19570

Closed
TomasMikula opened this issue Jan 30, 2024 · 1 comment · Fixed by #19644
Closed

Regression in GADT type inference inside polymorphic function #19570

TomasMikula opened this issue Jan 30, 2024 · 1 comment · Fixed by #19644
Assignees
Labels
area:gadt itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@TomasMikula
Copy link
Contributor

Compiler version

3.4.0-RC3
(regressed since 3.3.1)

Minimized code

enum Op[A, B]:
  case Dup[T]() extends Op[T, (T, T)]
    
def foo[R](f: [A, B] => (o: Op[A, B]) => R): R =
    f(Op.Dup())

foo([A, B] => (o: Op[A, B]) => {
  o match
    case o: Op.Dup[t] =>
      summon[A =:= t]      // ERROR: Cannot prove that A =:= t.
      summon[B =:= (t, t)] // ERROR: Cannot prove that B =:= (t, t).
      42
})

https://scastie.scala-lang.org/PvLamiXMQXaEIWEf18kGXQ

Output

Cannot prove that A =:= t.
Cannot prove that B =:= (t, t).

Expectation

The code should compile. It does compile with Scala 3.3.1

@TomasMikula TomasMikula added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 30, 2024
@EugeneFlesselle
Copy link
Contributor

EugeneFlesselle commented Jan 31, 2024

A perhaps minimised but more confusing version:

enum Op[A]:
  case Dup[T]() extends Op[(T, T)]

def foo[R](f: [A] => Op[A] => R): R = ??? 

def test =
  foo[Unit]([A] => (o: Op[A]) =>
    o match
      case o: Op.Dup[u] =>
        summon[A =:= (u, u)] // Ok
        ()
  )
  foo/*[Unit]*/([A] => (o: Op[A]) =>
    o match
      case o: Op.Dup[u] =>
        summon[A =:= (u, u)] // Error: Cannot prove that A =:= (u, u)
        ()
  )
  foo/*[Unit]*/(
    {
      val f1 = [B] => (o: Op[B]) =>
        o match
          case o: Op.Dup[u] =>
            summon[B =:= (u, u)] // Also ok
            ()
      f1
    }
  )

@Gedochao Gedochao added regression This worked in a previous version but doesn't anymore area:gadt and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 2, 2024
@dwijnand dwijnand self-assigned this Feb 7, 2024
@Kordyjan Kordyjan added this to the 3.4.1 milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:gadt itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants