Skip to content

Dependent types + Match types type resolution issue #19633

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
0lejk4 opened this issue Feb 6, 2024 · 4 comments · Fixed by #20013
Closed

Dependent types + Match types type resolution issue #19633

0lejk4 opened this issue Feb 6, 2024 · 4 comments · Fixed by #20013
Assignees
Labels
area:match-types area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@0lejk4
Copy link

0lejk4 commented Feb 6, 2024

Compiler version

3.4.0-RC4

Minimized code

object Repro {
  trait Responsive {
    type Response
  }

  object Responsive {
    type Aux[R] = Responsive {type Response = R}
    type Response[R] = R match {case Aux[r] => r}
  }

  case class StringRequest(name: String) extends Responsive {
    type Response = String
  }

  def withImplicit[R <: Responsive](request: R)(implicit ct: scala.reflect.ClassTag[Responsive.Response[R]]): Responsive.Response[R] = ???

  def withFunction[R <: Responsive](request: R)(call: R => Responsive.Response[R]): Responsive.Response[R] = ???

  def stringWithFunction(req: StringRequest): String = withFunction(req)(_.getClass.getSimpleName)

  def stringWithImplicit(req: StringRequest): String = withImplicit(req)

  def main(args: Array[String]): Unit = {}
}

Output

[error] -- [E007] Type Mismatch Error: /Projects/Scala3/src/main/scala/Main.scala:105:73 
[error] 105 |  def stringWithFunction(req: StringRequest): String = withFunction(req)(_.getClass.getSimpleName)
[error]     |                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |             Found:    Repro.StringRequest => String
[error]     |             Required: Repro.StringRequest =>
[error]     |               Repro.Responsive.Response[
[error]     |                 Repro.StringRequest]
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- [E172] Type Error: /Projects/Scala3/src/main/scala/Main.scala:107:72 
[error] 107 |  def stringWithImplicit(req: StringRequest): String = withImplicit(req)
[error]     |                                                                        ^
[error]     |No ClassTag available for Repro.Responsive.Response[
[error]     |  Repro.StringRequest]
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed

Expectation

Hello, decided to try out Scala 3.4.0-RC4 inside my project and found some strange behavior, this works on 3.3.1 and on 3.3.2-RC3.
If I explicitly fill the generic parameter error goes away.
Is this something that is already covered by existing issues or is this something new?

@0lejk4 0lejk4 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 6, 2024
@soronpo
Copy link
Contributor

soronpo commented Feb 8, 2024

Paging @sjrd

@Gedochao
Copy link
Contributor

Gedochao commented Feb 8, 2024

output from current main with -explain

-- [E007] Type Mismatch Error: repro.scala:19:73 -------------------------------
19 |  def stringWithFunction(req: StringRequest): String = withFunction(req)(_.getClass.getSimpleName)
   |                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^
   |Found:    Repro.StringRequest => String
   |Required: Repro.StringRequest => Repro.Responsive.Response[Repro.StringRequest]
   |----------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |
   | Tree: {
   |   def $anonfun(_$1: Repro.StringRequest):
   |     Repro.Responsive.Response[Repro.StringRequest] =
   |     _$1.getClass[Repro.StringRequest]().getSimpleName()
   |   closure($anonfun)
   | }
   | I tried to show that
   |   Repro.StringRequest => String
   | conforms to
   |   Repro.StringRequest => Repro.Responsive.Response[Repro.StringRequest]
   | but none of the attempts shown below succeeded:
   |
   |
   | The tests were made under a constraint with:
   |  uninstantiated variables:
   |  constrained types:
   |   [R <: Repro.Responsive]
   |     (request: R)
   |       (call: R => Repro.Responsive.Response[R]): Repro.Responsive.Response[R]
   |  bounds:
   |      R := Repro.StringRequest
   |  ordering:
   |  co-deps:
   |  contra-deps:
    ----------------------------------------------------------------------------
-- [E172] Type Error: repro.scala:21:72 ----------------------------------------
21 |  def stringWithImplicit(req: StringRequest): String = withImplicit(req)
   |                                                                        ^
   |No ClassTag available for Repro.Responsive.Response[Repro.StringRequest]
2 errors found

@Gedochao Gedochao added regression This worked in a previous version but doesn't anymore area:typer area:match-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 8, 2024
@sjrd
Copy link
Member

sjrd commented Feb 8, 2024

Probably a missing .normalized around class tag synthesizing.

@WojciechMazur
Copy link
Contributor

Bisect points to: 97725d7
Last good release: 3.4.0-RC1-bin-20231214-423cd6c-NIGHTLY
First bad release: 3.4.0-RC1-bin-20231218-ec2b8bc-NIGHTLY

sjrd added a commit to sjrd/dotty that referenced this issue Mar 25, 2024
Not sure what fixed it, but it seems to be good now.
@Gedochao Gedochao linked a pull request Mar 25, 2024 that will close this issue
sjrd added a commit that referenced this issue Mar 25, 2024
Not sure what fixed it, but it seems to be good now.
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
WojciechMazur pushed a commit that referenced this issue Jul 4, 2024
Not sure what fixed it, but it seems to be good now.

[Cherry-picked 230519f]
WojciechMazur added a commit that referenced this issue Jul 5, 2024
Backports #20013 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:match-types area:typer 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.

6 participants