scribe
scribe copied to clipboard
REPL: scribe macro NPE when the scala source file is virtual
Scala compiler can accept virtual source files, e.g. in the REPL (and e.g. a hypothetical improved Zinc implementation). In these cases the "jpath" of the SourceFile can be null, causing a crash:
scala> scribe.info("foo")
-- Error: ----------------------------------------------------------------------
1 |scribe.info("foo")
| ^
|Exception occurred while executing macro expansion.
|java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.getFileName()" because the return value of "scala.quoted.Quotes$reflectModule$SourceFileMethods.jpath(Object)" is null
| at sourcecode.Macros$.fileNameImpl(Macros.scala:155)
|
|----------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from Macros.scala:33
----------------------------------------------------------------------------
1 error found
For these virtual files the name and path properties should still have values
@bishabosha thanks for pointing this out. This appears to be a bug in https://github.com/com-lihaoyi/sourcecode causing this, but see the issue I linked above to get this resolved.
@bishabosha This should be fixed in the latest release.
nice!