Skip to content

Expr(null:String).show in macro throws NullPointerException #23008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Alexey-NM opened this issue Apr 16, 2025 · 1 comment
Open

Expr(null:String).show in macro throws NullPointerException #23008

Alexey-NM opened this issue Apr 16, 2025 · 1 comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug itype:crash Spree Suitable for a future Spree

Comments

@Alexey-NM
Copy link

Compiler version

3.6.4

Minimized code

Macro:

import scala.quoted.*

object ExprStringBugMacro {

  def buildStringCode(using Quotes): Expr[String] = {
    import quotes.reflect.*
    val str: String = null
    val exprString = Expr(str)
    //It throws NullPointerException
    println("Macro string: " + exprString.show)
    exprString
  }
}

Test:

import munit.FunSuite

class ExprStringBugTest extends munit.FunSuite {

  test("NullPoinreException") {
    buildString
  }

  implicit inline def buildString[T]: Unit = ${
    ExprStringBugMacro.buildStringCode
  }
}import scala.quoted.*

object ExprStringBugMacro {

  def buildStringCode(using Quotes): Expr[String] = {
    import quotes.reflect.*
    //Test value
    val str: String = null
    val exprString = Expr(str)
    println("Macro string: " + exprString.show)
    exprString
  }
}

Output

Image

Expectation

Absence of the exception

Description

stringValue

def stringValue: String = value.toString

just does not expect null.

It requres to implement a custom string converter to generate exp from java types.

@Alexey-NM Alexey-NM added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 16, 2025
@hamzaremmal hamzaremmal added itype:crash Spree Suitable for a future Spree area:metaprogramming:reflection Issues related to the quotes reflection API and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 16, 2025
@mbovel
Copy link
Member

mbovel commented Apr 28, 2025

This issue was picked for the Scala Issue Spree of today, Monday, April 28th! @hamzaremmal, @mbovel, @HarrisL2 and @ajafri2001 will be working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug itype:crash Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

3 participants