Skip to content

Commit 898ce33

Browse files
authored
Add patch for undefined behavior with object $ (#19705)
Add an ad-hoc patch to make it possible to use the broken `object $` definitions in https://github.com/com-lihaoyi/Ammonite/blob/main/amm/interp/api/src/main/scala/ammonite/Stubs.scala. This is a temporary patch while these definitions get deprecated. There is not guarantee that the semantics of these objects are correct. There is also no way to adapt the spec to allow there definition without breaking the language. For example consider `object $` and `object $$`, how would we know if the `$$.class` is the class of `$$` or the module class of `$`. We need to know this before we read the file. Closes #19702
2 parents 69170d3 + b0b6ec5 commit 898ce33

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ object FileUtils {
114114
if classOrModuleName.endsWith("$")
115115
&& classOrModuleName != "Null$" // scala.runtime.Null$
116116
&& classOrModuleName != "Nothing$" // scala.runtime.Nothing$
117+
// Special case for `object $` in Amonite.
118+
// This is an ad-hoc workaround for Amonite `object $`. See issue #19702
119+
// This definition is not valid Scala.
120+
&& classOrModuleName != "$"
117121
then classOrModuleName.stripSuffix("$")
118122
else classOrModuleName
119123
className + SUFFIX_TASTY

tests/pos/i19702/Macro_1.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test
2+
3+
// IMPORTANT: this object has undefined behavior due to its illegal use of a $ in an identifier
4+
// This test is only to check that the ad-hoc workaround for Amonite `object $` is working.
5+
// If at some point it becomes impossible to support this test, we can drop it.
6+
// Ideally Amonite will have deprecated the `object $` by then.
7+
object $ {
8+
def test(): Int = 1
9+
}

tests/pos/i19702/Test_2.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@main def hello =
2+
test.$.test()
3+
4+
println("?")

0 commit comments

Comments
 (0)