Open Glavo opened 6 years ago
This Scala object can be compiled:
object Main {
def main(args: Array[String]): Unit = {
val c = new C
println(c.+)
println(c.`+`)
}
}
However, problems occur at runtime:
glavo@glavo:~/Document/Test$ dotr -classpath .:/home/glavo/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.4668.68/plugins/Kotlin/lib/kotlin-stdlib.jar Main Exception in thread "main" java.lang.NoSuchMethodError: C.$plus()I at Main$.main(Main.scala:4) at Main.main(Main.scala)
I haven't tested it in the IDE, but I think that the IDE's completion and error hints cause similar problems.
Can Scalac call that function? Right now Scala interoperates with Java and Scala, and AFAIK neither can produce such classes, so we can safely assume we can mangle symbolic names. Changing that assumption risks being pretty invasive...
@Blaisorblade Scalac seems to ignore this method.
glavo@glavo:~/文档/Test$ scalac Main.scala Main.scala:4: error: missing argument list for method + in class any2stringadd Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing `+ _` or `+(_)` instead of `+`. println(c.+) ^ Main.scala:5: error: missing argument list for method + in class any2stringadd Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing `+ _` or `+(_)` instead of `+`. println(c.`+`) ^ two errors found
I guess the sensible thing to do is to ignore class files that don't originate from eitheir a Java source file or a Scala source file
I guess the sensible thing to do is to ignore class files that don't originate from eitheir a Java source file or a Scala source file
That's way too extreme. First, it's impossible to know how a classfile was produced in general. Second, it's possible to produce Kotlin classes that are usable from Scala, since it's possible to make them usable from Java.
A less extreme solution would be to not encode names that don't come from scala
Here's a Kotlin class:
When I use it in repl, the completion can suggest the
+
method:However, problems occur when calling: