Skip to content

Scala 3.8 macros using Option.orNull cannot be consumed on Scala 3.9 #26626

Description

@WojciechMazur

Based on the OpenCB failure in sangria-graphql/sangria - build logs

Compiler version

3.9.0-RC4

Most likely caused by #25733

Minimized code

// macro.scala
//> using scala 3.8.4

package sangria

import scala.quoted.*

object Macros:
  inline def useOrNull[T](inline o: Option[T]): T =
    ${ useOrNullImpl('o) }

  def useOrNullImpl[T: Type](o: Expr[Option[T]])(using Quotes): Expr[T] =
    '{ $o.orNull.asInstanceOf[T] }
// test.scala 
//> using jar sangria-macros.jar
//> using scala 3.9.0-RC4

object AstVisitor:
  def visit(o: Option[String]): String = sangria.Macros.useOrNull(o)

Reproduction steps:

scala package macro.scala --library -o sangria-macros.jar -f
scala compile test.scala 

Output

Compiling project (Scala 3.9.0-RC4, JVM (25))
[error] ./sangria.scala:5:42
[error] illegal access to protected method orNull in class Option from object AstVisitor
[error]   def visit(o: Option[String]): String = sangria.Macros.useOrNull(o)
[error]                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expectation

Macro produced with older version of Scala should still be valid when used on newer compiler due to backward compatibility guarantees

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions