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

Tuple decomposition in quotes pattern matching doesn't compile #16265

Closed
prolativ opened this issue Oct 31, 2022 · 3 comments · Fixed by #16710
Closed

Tuple decomposition in quotes pattern matching doesn't compile #16265

prolativ opened this issue Oct 31, 2022 · 3 comments · Fixed by #16710
Assignees
Labels
area:gadt area:match-types itype:bug regression This worked in a previous version but doesn't anymore

Comments

@prolativ
Copy link
Contributor

Compiler version

Fails with: 3.2.1, 3.2.2-RC1-bin-20221030-eab19e3-NIGHTLY
Used to work with 3.2.0

Minimized code

//> using scala "3.2.1"

import scala.quoted.*

class Foo(val value: Int)
  
def foo(exprs: Expr[Any])(using Quotes): Any =
  exprs match
    case '{ $tuple: (Foo *: tail) } =>
      val x = '{ ${tuple}.head.value }
      ???

Output

[error] ./repro/Macro.scala:10:18: undefined: ${
[error]   {
[error]     def $anonfun(using evidence$1: quoted.Quotes): quoted.Expr[(Foo *: tail)] = 
[error]       tuple
[error]     closure($anonfun)
[error]   }
[error] }.head[(Foo *: tail)].value.$asInstanceOf # -1: TermRef(TermRef(AppliedType(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Tuple),Head),List(AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class *:),List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Foo), TypeRef(NoPrefix,type tail))))),value),$asInstanceOf$) at sbt-api
[error]       val x = '{ ${tuple}.head.value }
[error]

Expectation

Should compile, as in 3.2.0

@prolativ prolativ 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 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 Oct 31, 2022
@dwijnand
Copy link
Member

dwijnand commented Nov 5, 2022

This fails during the type assigning of the TypeApply for "$asInstanceOf$" (which for some reason prints as "$asInstanceOf") during post-typer (even though for some reason "at sbt-api" is printed...). The type assigner wants the widened TypeLambda instead finds a TermRef with NoType as its widening. The TermRef is Tuple.Head[Foo *: tail]#value.$asInstanceOf.type. During typer, while GADT constraints are still present, that's type is (Foo#value : Int) & Int, because Tuple.Head[Foo *: tail] can reduce to Foo.

So GADT constraints/casting and Match Type reduction/caching issues, AFAICT.

(edit) Oh, and where did that cast come from? From GADT casting of course..

@dwijnand dwijnand added area:match-types area:gadt and removed area:metaprogramming:quotes Issues related to quotes and splices labels Nov 5, 2022
@prolativ
Copy link
Contributor Author

Bisected to #15872

@nicolasstucki
Copy link
Contributor

This works now

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 17, 2023
Kordyjan added a commit that referenced this issue Jan 18, 2023
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:gadt 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.

4 participants