Skip to content

Exception occurred while executing macro expansion. java.lang.VerifyError: Bad type on operand stack #15400

Closed
@svenkeidel

Description

@svenkeidel

Compiler version

3.1.2

Minimized code

import scala.quoted.{Expr, Quotes, Type}

object Macros {
  enum Free[A, B](using val typeDom: Type[A], val typeCod: Type[B]):
    case Id[A: Type]() extends Free[A,A]
    case Product[A: Type, B: Type, C: Type](f: Free[A,B], g: Free[A,C])(using quotes: Quotes)
      extends Free[A,(B,C)](using typeCod = Type.of[(B,C)])

  def test[A: Type]()(using quotes: Quotes): Expr[Unit] =
    val prod = Free.Product[A,A,A](Free.Id[A](), Free.Id[A]())
    '{ () }

  inline def testInline[A](): Unit = ${ test[A]() }
}

Output (click arrow to expand)

Calling testInline[Int]() results in the following exception

Exception occurred while executing macro expansion.
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Free$Product.<init>(LMacros$Free;LMacros$Free;Lscala/quoted/Type;Lscala/quoted/Type;Lscala/quoted/Type;Lscala/quoted/Quotes;)V @34: invokedynamic
  Reason:
    Type uninitializedThis (current frame, stack[2]) is not assignable to 'Macros$Free$Product'
  Current Frame:
    bci: @34
    flags: { flagThisUninit }
    locals: { uninitializedThis, 'Macros$Free', 'Macros$Free', 'scala/quoted/Type', 'scala/quoted/Type', 'scala/quoted/Type', 'scala/quoted/Quotes' }
    stack: { 'scala/quoted/runtime/QuoteUnpickler', 'java/lang/String', uninitializedThis, 'scala/quoted/Type', 'scala/quoted/Type' }
  Bytecode:
    0000000: 2a2b b500 2d2a 2cb5 002f 2a19 04b5 0031
    0000010: 2a19 05b5 0033 1906 c000 3512 372a 1904
    0000020: 1905 ba00 4c00 0001 b900 5004 003a 072a
    0000030: 2d19 07b7 0053 b1                      

	at Macros$Free$Product$.apply(Macros.scala:8)
	at Macros$.test(Macros.scala:12)

        testInline[Int]()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions