Skip to content

Exprs that take a NamedTuple argument (but not <: AnyNamedTuple) can't be matched against when the method that calls the macro is transparent inline #23412

Open
@arainko

Description

@arainko

Compiler version

3.7.1, 3.7.3-RC1-bin-20250620-d6b74fa-NIGHTLY

Minimized code

//> using scala 3.7.1
// file: Repro2.scala

import NamedTuple.*
import scala.quoted.*

class ReproClass {
  def methodCallWithNamedTuple[Names <: Tuple, Values <: Tuple](tup: NamedTuple[Names, Values]): Int = 1
  def methodCallWithAnyNamedTuple[Tup <: AnyNamedTuple](tup: Tup): Int = 1
}

object Repro2 {
  // works correctly if this is defined as just `inline`
  transparent inline def run(inline expr: Int) = ${ runMacro('expr) }

  def runMacro(expr: Expr[Int])(using Quotes) = {
    import quotes.reflect.*

    expr match {
      case '{ 
        type names <: Tuple
        type values <: Tuple
        ($reproClass: ReproClass).methodCallWithNamedTuple[names, values]($tup) 
      } => report.errorAndAbort("Matched methodCallWithNamedTuple")

      case '{ 
        type tup <: AnyNamedTuple
        ($reproClass: ReproClass).methodCallWithAnyNamedTuple[tup]($tup) 
      } => report.errorAndAbort("Matched methodCallWithAnyNamedTuple")

      case _ => report.errorAndAbort("didn't match anything :c")
    }
    
  }
}
//file test2.scala

object test2 {
  val reproClass = new ReproClass
  Repro2.run(reproClass.methodCallWithNamedTuple((field1 = 123, field2 = "123"))) // didn't match anything :c
  Repro2.run(reproClass.methodCallWithAnyNamedTuple((field1 = 123, field2 = "123"))) // Matched methodWithAnyNamedTuple
}

Output

Compiling project (Scala 3.7.3-RC1-bin-20250620-d6b74fa-NIGHTLY, JVM (21))
[error] ./unableToMatchExprsThatEvenMentionNamedTuple/test2.scala:3:3
[error] didn't match anything :c
[error]   Repro2.run(reproClass.methodCallWithNamedTuple((field1 = 123, field2 = "123"))) // didn't match anything :c
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] ./unableToMatchExprsThatEvenMentionNamedTuple/test2.scala:4:3
[error] Matched methodCallWithAnyNamedTuple
[error]   Repro2.run(reproClass.methodCallWithAnyNamedTuple((field1 = 123, field2 = "123"))) // Matched methodWithAnyNamedTuple
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.7.3-RC1-bin-20250620-d6b74fa-NIGHTLY, JVM (21))
Compilation failed

Expectation

Repro2.run(reproClass.methodCallWithNamedTuple((field1 = 123, field2 = "123"))) outputs Matched methodCallWithNamedTuple when Repro2.run is defined as inline or transparent inline

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions