diff --git a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala index 8c31faa43186..b8cb9a2155dc 100644 --- a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala +++ b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala @@ -114,6 +114,10 @@ object FileUtils { if classOrModuleName.endsWith("$") && classOrModuleName != "Null$" // scala.runtime.Null$ && classOrModuleName != "Nothing$" // scala.runtime.Nothing$ + // Special case for `object $` in Amonite. + // This is an ad-hoc workaround for Amonite `object $`. See issue #19702 + // This definition is not valid Scala. + && classOrModuleName != "$" then classOrModuleName.stripSuffix("$") else classOrModuleName className + SUFFIX_TASTY diff --git a/tests/pos/i19702/Macro_1.scala b/tests/pos/i19702/Macro_1.scala new file mode 100644 index 000000000000..79aab856dfda --- /dev/null +++ b/tests/pos/i19702/Macro_1.scala @@ -0,0 +1,9 @@ +package test + +// IMPORTANT: this object has undefined behavior due to its illegal use of a $ in an identifier +// This test is only to check that the ad-hoc workaround for Amonite `object $` is working. +// If at some point it becomes impossible to support this test, we can drop it. +// Ideally Amonite will have deprecated the `object $` by then. +object $ { + def test(): Int = 1 +} diff --git a/tests/pos/i19702/Test_2.scala b/tests/pos/i19702/Test_2.scala new file mode 100644 index 000000000000..c8bcd4287e0d --- /dev/null +++ b/tests/pos/i19702/Test_2.scala @@ -0,0 +1,4 @@ +@main def hello = + test.$.test() + + println("?")