Skip to content

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

Closed
@prolativ

Description

@prolativ

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 }  
  }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions