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 3.4.0+: scenario where Tuple.InverseMap does not compute the expected type #20538

Closed
kavedaa opened this issue Jun 9, 2024 · 8 comments · Fixed by #21198
Closed
Assignees
Labels
area:match-types itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@kavedaa
Copy link

kavedaa commented Jun 9, 2024

Compiler version

3.4.0 and higher

Minimized code

//> using scala 3.4.0

trait Column:
  type T
  type F[X]
  type Q = F[T]

class varchar extends Column:
  type T = String

trait notnull extends Column:
  type F[X] = X

object Error:

  val firstName = new varchar with notnull
  val lastName = new varchar with notnull

  val relation = (firstName, lastName)

  type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }]

  summon[RelationTypes =:= (String, String)]

object Works:

  object firstName extends varchar with notnull
  object lastName extends varchar with notnull

  val relation = (firstName, lastName)

  type RelationTypes = Tuple.InverseMap[relation.type, [X] =>> Column { type Q = X }]

  summon[RelationTypes =:= (String, String)]

Output

Compiling project (Scala 3.4.0, JVM (8))
[error] .\test.scala:23:45
[error] Cannot prove that Error.RelationTypes =:= (String, String).
[error]   summon[RelationTypes =:= (String, String)]
[error]                                             ^
Error compiling project (Scala 3.4.0, JVM (8))
Compilation failed

Expectation

Successful compilation.

@kavedaa kavedaa added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 9, 2024
@kavedaa
Copy link
Author

kavedaa commented Jun 9, 2024

Compiles in 3.3.3.

Could perhaps be related to #17222?

@Gedochao Gedochao added area:implicits related to implicits regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 11, 2024
@kavedaa
Copy link
Author

kavedaa commented Jun 14, 2024

Regression happens in 3.4.0-RC1-bin-20231218-ec2b8bc-NIGHTLY:

Compiling project (Scala 3.4.0-RC1-bin-20231218-ec2b8bc-NIGHTLY, JVM (8))
[error] .\test.scala:23:45
[error] Cannot prove that Error.RelationTypes =:= (String, String).
[error]   summon[RelationTypes =:= (String, String)]
[error]                                             ^
Error compiling project (Scala 3.4.0-RC1-bin-20231218-ec2b8bc-NIGHTLY, JVM (8))
Compiling project (Scala 3.4.0-RC1-bin-20231214-423cd6c-NIGHTLY, JVM (8))
Compiled project (Scala 3.4.0-RC1-bin-20231214-423cd6c-NIGHTLY, JVM (8))

@EugeneFlesselle
Copy link
Contributor

EugeneFlesselle commented Jul 3, 2024

Minimized to:

trait A:
  type T
  type U = T

trait B extends A:
  type T = String

object C extends B


type F[X] = A { type U = X } // works when `U` is replaced with `T`

type InvF[Y] = Y match
  case F[x] => x


object Test:
  summon[InvF[C.type] =:= String] // ok
  summon[InvF[B] =:= String] // error: selector B does not uniquely determine parameter x

although I'm not 100% sure this an incorrect error.

@jchyb
Copy link
Contributor

jchyb commented Jul 8, 2024

After investigating #17222, these two issues are probably unrelated

@mbovel
Copy link
Member

mbovel commented Jul 15, 2024

This issue is fixed by #20161: adding import language.experimental.betterMatchTypeExtractors enabled to compile both the @EugeneFlesselle's minimization @kavedaa's original snippet.

Adding the import does not fix #17222.

@smarter would you have any insights on when the amendment will be stabilized?

Should I just add regression tests and mark this issue as solved?

@EugeneFlesselle EugeneFlesselle added area:match-types and removed area:implicits related to implicits labels Jul 15, 2024
@smarter
Copy link
Member

smarter commented Jul 15, 2024

It needs a minor release so it should be in 3.6.0

@mbovel
Copy link
Member

mbovel commented Jul 15, 2024

Wonderful, so this means these examples will compile just fine in 3.6!

I suggest we add regressions tests with import language.experimental.betterMatchTypeExtractors and close this issue already. When 3.6 is released, we can remove the imports in the tests. Sound okay?

@EugeneFlesselle
Copy link
Contributor

I suggest we add regressions tests with import language.experimental.betterMatchTypeExtractors

IIRC tests usually have scala-cli directives for experimental options but sounds fine to me either way

@WojciechMazur WojciechMazur added this to the 3.6.0 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:match-types 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.

7 participants