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

Quoted patterns regression: match with Underlying type fails #16522

Closed
hmf opened this issue Dec 14, 2022 · 2 comments · Fixed by #18133
Closed

Quoted patterns regression: match with Underlying type fails #16522

hmf opened this issue Dec 14, 2022 · 2 comments · Fixed by #18133
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:enhancement
Milestone

Comments

@hmf
Copy link

hmf commented Dec 14, 2022

Compiler version

Compiler version 3.2.1

Minimized code

This is the code that worked when discussed in issue #10358. I am reporting it here so that it does not slip through the cracks (discussed in November 2020):

  import scala.quoted.*

  sealed trait HList
  case class HCons[+HD, TL <: HList](hd: HD, tl: TL) extends HList
  case object HNil extends HList

  def showFirstTwoImpl(e: Expr[HList])(using Quotes): Expr[String] = {
    e match {
      // Ok. No match 
      case '{HCons($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString}
      // Fails. Does not compile 
      case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString}
      // Ok
      case '{HCons[hd, HCons[sd, tl]]($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString}
      case _ => '{""}
    }
  }

  transparent inline def showFirstTwo(inline xs: HList) = ${ showFirstTwoImpl('xs) }  

Output

error] -- [E007] Type Mismatch Error: /home/hmf/VSCodeProjects/sploty/meta/src/data/Macros3.scala:1184:45 
[error] 1184 |      case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString}
[error]      |                                             ^^^^^^^
[error]      |                                      Found:    tl$given2.Underlying
[error]      |                                      Required: data.Macros3.HList
[error]      |--------------------------------------------------------------------------
[error]      | Explanation (enabled by `-explain`)
Compiler explanation:
error]      |
[error]      | Tree: ${_}:(tl$given2 @ _).Underlying
[error]      | I tried to show that
[error]      |   tl$given2.Underlying
[error]      | conforms to
[error]      |   TL
[error]      | but the comparison trace ended with `false`:
[error]      |
[error]      |   ==> tl$given2.Underlying  <:  TL
[error]      |     ==> tl$given2.Underlying  <:  TL
[error]      |       ==> tl  <:  TL
[error]      |         ==> tl  <:  TL in frozen constraint
[error]      |           ==> tl  <:  Nothing in frozen constraint
[error]      |             ==> Any  <:  Nothing (left is approximated) in frozen constraint
[error]      |             <== Any  <:  Nothing (left is approximated) in frozen constraint = false
[error]      |           <== tl  <:  Nothing in frozen constraint = false
[error]      |           ==> Any  <:  TL (left is approximated) in frozen constraint
[error]      |             ==> Any  <:  Nothing (left is approximated) in frozen constraint
[error]      |             <== Any  <:  Nothing (left is approximated) in frozen constraint = false
[error]      |           <== Any  <:  TL (left is approximated) in frozen constraint = false
[error]      |         <== tl  <:  TL in frozen constraint = false
[error]      |         ==> add constraint TL >: tl , constraint =  uninstantiated variables: TL, HD, TL, HD, TL, HD, TL, HD, TL  constrained types:    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL] , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL],    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL] , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL],    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL]  bounds:       HD := Any      TL >: data.Macros3.HCons[Any, data.Macros3.HList] <: data.Macros3.HList      HD      TL <: data.Macros3.HList      HD >: hd1      TL >: data.Macros3.HCons[HD, TL] <: data.Macros3.HList      HD      TL <: data.Macros3.HList      HD >: hd2      TL <: data.Macros3.HList  ordering: 
[error]      |           ==> lub(Nothing, tl, canConstrain=false, isSoft=true)
[error]      |           <== lub(Nothing, tl, canConstrain=false, isSoft=true) = tl
[error]      |           ==> tl  <:  data.Macros3.HList
[error]      |             ==> Any  <:  data.Macros3.HList (left is approximated)
[error]      |             <== Any  <:  data.Macros3.HList (left is approximated) = false
[error]      |           <== tl  <:  data.Macros3.HList = false
[error]      |         <== add constraint TL >: tl , constraint =  uninstantiated variables: TL, HD, TL, HD, TL, HD, TL, HD, TL  constrained types:    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL] , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL],    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL] , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL],    [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL]  bounds:       HD := Any      TL >: data.Macros3.HCons[Any, data.Macros3.HList] <: data.Macros3.HList      HD      TL <: data.Macros3.HList      HD >: hd1      TL >: data.Macros3.HCons[HD, TL] <: data.Macros3.HList      HD      TL <: data.Macros3.HList      HD >: hd2      TL <: data.Macros3.HList  ordering:  = false
[error]      |       <== tl  <:  TL = false
[error]      |     <== tl$given2.Underlying  <:  TL = false
[error]      |   <== tl$given2.Underlying  <:  TL = false
[error]      |
[error]      | The tests were made under a constraint with:
[error]      |  uninstantiated variables: TL, HD, TL, HD, TL, HD, TL, HD, TL
[error]      |  constrained types: 
[error]      |   [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL]
[error]      | , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL], 
[error]      |   [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL]
[error]      | , [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL], 
[error]      |   [HD, TL <: data.Macros3.HList](hd: HD, tl: TL): data.Macros3.HCons[HD, TL]
[error]      |  bounds: 
[error]      |      HD := Any
[error]      |      TL >: data.Macros3.HCons[Any, data.Macros3.HList] <: data.Macros3.HList
[error]      |      HD
[error]      |      TL <: data.Macros3.HList
[error]      |      HD >: hd1
[error]      |      TL >: data.Macros3.HCons[HD, TL] <: data.Macros3.HList
[error]      |      HD
[error]      |      TL <: data.Macros3.HList
[error]      |      HD >: hd2
[error]      |      TL <: data.Macros3.HList
[error]      |  ordering: 
[error]       --------------------------------------------------------------------------

Expectation

Expect the code in #10358 to keep working on the latest compiler.

@hmf hmf added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 14, 2022
@hmf hmf changed the title Quoted patterns regression: match with Quoted patterns regression: match with Underlying type fails Dec 14, 2022
@anatoliykmetyuk anatoliykmetyuk added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 19, 2022
@nicolasstucki
Copy link
Contributor

We do not infer the bounds for that tl. You can add explicit bound to make it work.

-      case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => 
+      case '{type tl <: HList; HCons($h1: hd1, HCons($h2: hd2, $_ : `tl`))} => 

@nicolasstucki
Copy link
Contributor

#18133 will fix the error message.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 13, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants