scribe icon indicating copy to clipboard operation
scribe copied to clipboard

REPL: scribe macro NPE when the scala source file is virtual

Open bishabosha opened this issue 2 years ago • 2 comments

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

bishabosha avatar Feb 05 '23 11:02 bishabosha

For these virtual files the name and path properties should still have values

bishabosha avatar Feb 05 '23 11:02 bishabosha

@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.

darkfrog26 avatar Feb 05 '23 18:02 darkfrog26

@bishabosha This should be fixed in the latest release.

darkfrog26 avatar Apr 18 '24 18:04 darkfrog26

nice!

bishabosha avatar Apr 18 '24 20:04 bishabosha