Skip to content

Unused type parameter of kind * -> * doesn't allow proving subtyping of other type parameters #15677

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

Closed
KacperFKorban opened this issue Jul 14, 2022 · 1 comment · Fixed by #15688
Assignees
Labels
area:gadt itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@KacperFKorban
Copy link
Member

Compiler version

Compiles correctly for 3.0.0, 3.0.1
Gives an error for 3.0.2
Compiles correctly for 3.1.0, 3.1.1
Gives an error for 3.1.2, 3.1.3, 3.2.0-RC1, 3.2.1-RC1-bin-20220712-7e20b81-NIGHTLY

Minimized code

class Interval[E, D[_]]
class BoundedAbove[E, D[_]] extends Interval[E, D] {
  def upper: Upper[E] = ???
}
class Upper[E]

def reference: Interval[Int, Option] = ???

def bound: Upper[Int] =
  reference match {
    case int: BoundedAbove[_, _] => int.upper
    case _ => null
  }

Output

[error] ./main.scala:13:37: Found:    Upper[_]
[error] Required: Upper[Int]
[error]     case int: BoundedAbove[_, _] => int.upper
[error]                                     ^^^^^^^^^

Expectation

Compile correctly.
It should be possible to prove that int.upper.type <:< Upper[Int]

More information

Interestingly, the following piece of code compiles correctly. (If we change the kind of D to * or remove it altogether)

class Interval[E, D]
class BoundedAbove[E, D] extends Interval[E, D] {
  def upper: Upper[E] = ???
}
class Upper[E]

def reference: Interval[Int, String] = ???

def bound: Upper[Int] =
  reference match {
    case int: BoundedAbove[_, _] => int.upper
    case _ => null
  }
@KacperFKorban KacperFKorban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label regression This worked in a previous version but doesn't anymore labels Jul 14, 2022
@mbovel
Copy link
Member

mbovel commented Jul 15, 2022

First bad commit is 2f16cc7:

$ mv project/scripts/dottyCompileBisect.sh ..
$ chmod +x ../dottyCompileBisect.sh
$ git bisect bad main 
$ git bisect good 741e17e7e5
$ git bisect run ../dottyCompileBisect.sh test.scala
...
2f16cc7142dedd9225496aa131ebfbe547dc6b9c is the first bad commit
commit 2f16cc7142dedd9225496aa131ebfbe547dc6b9c
Author: Dale Wijnand <[email protected]>
Date:   Sat Dec 18 05:27:11 2021 +0000

    Extract GADT constraints from wildcard type arguments

https://github.com/lampepfl/dotty/blob/2f16cc7142dedd9225496aa131ebfbe547dc6b9c/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala#L259-L265

@mbovel mbovel added area:gadt and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 15, 2022
@dwijnand dwijnand linked a pull request Jul 16, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
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.

4 participants