Skip to content

Quoted function matching fails when matching on a function that outputs an intersection type #25238

@arainko

Description

@arainko

Compiler version

3.3.7, 3.8.1

Minimized code

// file: macro.scala
import scala.quoted.*

object ModifierParser {
  inline def use[A](inline mod: TupleModifier[A] => TupleModifier[A]) = ${ parse('mod) }

  def parse[A](mod: Expr[TupleModifier[A] => TupleModifier[A]])(using Quotes): Expr[Unit] = {
    import quotes.reflect.*

    mod match {
      case '{ (builder: TupleModifier[tup]) => builder.renameNotRegional } =>
        report.errorAndAbort("Matched 'renameNotRegional'")
      case '{ (builder: TupleModifier[tup]) => builder.rename } =>
        report.errorAndAbort("Matched 'rename'")
      case '{ (builder: TupleModifier[tup]) => builder.rename.regional[a] } =>
        report.errorAndAbort("Matched 'rename.regional'")
      case _ => report.errorAndAbort("No match :c")
    }
  }
}
// file: TupleModifier.scala
//> using scala 3.8.1

sealed trait TupleModifier[Tup] {
  def rename: TupleModifier[Tup] & Regional[Tup]
  def renameNotRegional: TupleModifier[Tup]
}

sealed trait Regional[Tup]

object Regional {
  extension [Tup](self: TupleModifier[Tup] & Regional[Tup]) {
    def regional[Selected]: TupleModifier[Tup] = ???
  }
}

object usage {
  ModifierParser.use(_.rename) // No match :c

  ModifierParser.use(_.rename.regional) // Matched 'rename.regional'

  ModifierParser.use(_.renameNotRegional) // Matched 'renameNotRegional'
}

Output

$ scala compile .
Compiling project (Scala 3.8.1, JVM (17))
[error] ./TupleModifier.scala:17:3
[error] No match :c
[error]   ModifierParser.use(_.rename) // No match :c
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] ./TupleModifier.scala:19:3
[error] MATCHED 'rename.regional'
[error]   ModifierParser.use(_.rename.regional) // Matched 'rename.regional'
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] ./TupleModifier.scala:21:3
[error] MATCHED 'renameNotRegional'
[error]   ModifierParser.use(_.renameNotRegional) // Matched 'renameNotRegional'
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.8.1, JVM (17))
Compilation failed

Expectation

I'd expect ModifierParser.use(_.rename) to output Matched 'rename'

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions