Scala 3 macros does not generate error on giving a non existent symbol

With Scal 3 macros the following works for any value provided. When I compile I get the output The symbol is object <whatever value I give>.

//..inside a macro function
val symbol = Symbol.requiredPackage("alsdkfjsdlkfj") //Works for any random value here
println(s"The symbol is $symbol") //This prints "The symbol is object alsdkfjsdlkfj"

But such a package does not exist. Shouldn’t this give a compilation error? The doc for requiredPackage method says Get package symbol if package is either defined in current compilation run or present on classpath. I am assuming that if the package is not defined in current compilation run or present on classpath it should fail.


I am trying out Scala 3 macros from this project. The linked page contains the complete source code. Search for the line val symbol = Symbol.requiredPackage(packageName) in object PackageSearch

A full code snippet would be needed to say what might be wrong here. E.g. this might not break if you only define such a macro but don’t call it anywhere. Or if you use requiredPackage to get a reference to a symbol but you don’t actually use this symbol or the reference gets removed from the syntax tree at some stage of compilation.

thanks, I have edited my post to include the link to the complete source code.

Ok, this is indeed quite strange. I would recommend reporting this as an issue to the compiler’s repository with a minimized self-contained snippet of code showing the problem

Or maybe @nicolasstucki could say something more if this is the expected behaviour

1 Like

It seems it should fail if the package is not on the classpath. This looks like a bug. I would assume that noSymbol would be returned if the package did not exist.

1 Like

Could you open an issue on GitHub?

1 Like

sure, I will do that

@nicolasstucki done Report an error when package is not on classpath · Issue #16656 · lampepfl/dotty · GitHub