Skip to content

Using Quotes inside the body of a destructuring lambda breaks type inference #15715

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
prolativ opened this issue Jul 21, 2022 · 1 comment · Fixed by #18105
Closed

Using Quotes inside the body of a destructuring lambda breaks type inference #15715

prolativ opened this issue Jul 21, 2022 · 1 comment · Fixed by #18105
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@prolativ
Copy link
Contributor

Compiler version

3.2.1-RC1-bin-20220720-6c7acf9-NIGHTLY and earlier

Minimized code

//> using scala "3.2.1-RC1-bin-20220720-6c7acf9-NIGHTLY"

import scala.quoted.*

def macroImpl(using Quotes) =
  val expr = Expr(1)
  Some((1, 2)).map { (x, y) =>
    '{ ${expr} + 1 }  
  }

Output

[error] MacroMap.scala:8:5: Found:    (x$1 : (Int, Int))
[error] Required: quoted.Quotes
[error]     '{ ${expr} + 1 }  
[error]     ^

Expectation

This should compile successfully as it does when the lambda takes a single parameter which gets destructured later on, e.g.

  Some((1, 2)).map { tuple =>
    val (x, y) = tuple
    '{ ${expr} + 1 }  
  }

An alternative workaround is to make the body of the lambda a context function explicitly

  Some((1, 2)).map { (x, y) => (q: Quotes) ?=>
    '{ ${expr} + 1 }  
  }
@prolativ prolativ added itype:bug area:metaprogramming:quotes Issues related to quotes and splices labels Jul 21, 2022
@prolativ
Copy link
Contributor Author

Actually it looks like the second workaround makes things compile in this particular case but then the result type is different: Option[Quotes ?=> Expr[Int]] instead of Option[Expr[Int]].
Actually working workaround:

def macroImpl(using q: Quotes): Option[Expr[Int]] =
  val expr = Expr(1)
  Some((1, 2)).map { (x, y) =>
    given Quotes = q
    '{ ${expr} + 1 }  
  }

jchyb added a commit to jchyb/dotty that referenced this issue Jun 30, 2023
jchyb added a commit to jchyb/dotty that referenced this issue Jun 30, 2023
jchyb added a commit to jchyb/dotty that referenced this issue Jun 30, 2023
Kordyjan added a commit that referenced this issue Jun 30, 2023
Closes #15715 
Also seems fixed in 3.3.1-RC1
Kordyjan pushed a commit that referenced this issue Nov 23, 2023
Kordyjan pushed a commit that referenced this issue Nov 29, 2023
Kordyjan added a commit that referenced this issue Dec 8, 2023
Backports #18105 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:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants