Skip to content
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

Add patch for undefined behavior with object $ #19705

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/classpath/FileUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so for clarity object $ makes $$.class, $.class, and $.tasty.
$$.class => $.tasty via standard code path
$.class => $.tasty via this escape hatch

then classOrModuleName.stripSuffix("$")
else classOrModuleName
className + SUFFIX_TASTY
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i19702/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions tests/pos/i19702/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@main def hello =
test.$.test()

println("?")
Loading