You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While preparing a recent contest, we found out that Kotlin does not only capitalize the first letter of the file, but also renames the main class to make it a valid Java class name. For example: test-test.kt is compiled to Test_test.class (note how the hyphen turns into an underscore). See the script below for a couple of weird filenames that I tested with.
Script used for testing names
fornameintest Test test-1 test-test Têśt 'test+&~$test'doechoecho$nameecho'val x = 42'>$name.kt
kotlinc $name.kt
ls *.class
rm -f *.class *.kt
done
$ ./test.sh
test
TestKt.class
Test
TestKt.class
test-1
Test_1Kt.class
test-test
Test_testKt.class
Têśt
error: source file or directory not found: T????t.kt
ls: cannot access '*.class': No such file or directory
test+&~$test
Test____testKt.class
The problem with this "name mangling" is that Kotlin does document that this happens, just not how exactly. We could add in a string replace that turns every non-alphanumeric character into an underscore (_), but that only solves part of the problem: there might be characters that get a different treatment than just turning them into underscores, and files with non-ASCII characters apparently don't even compile (e.g. Têśt.kt).
One thing I did figure out: kotlinc dumps the name of the compiled class in META-INF/main.kotlin_module, so we could fetch it from there, but I'm not sure how that would fit in the problemtools pipeline.
The text was updated successfully, but these errors were encountered:
Follow-up of #124.
While preparing a recent contest, we found out that Kotlin does not only capitalize the first letter of the file, but also renames the main class to make it a valid Java class name. For example:
test-test.kt
is compiled toTest_test.class
(note how the hyphen turns into an underscore). See the script below for a couple of weird filenames that I tested with.Script used for testing names
The problem with this "name mangling" is that Kotlin does document that this happens, just not how exactly. We could add in a string
replace
that turns every non-alphanumeric character into an underscore (_
), but that only solves part of the problem: there might be characters that get a different treatment than just turning them into underscores, and files with non-ASCII characters apparently don't even compile (e.g.Têśt.kt
).One thing I did figure out:
kotlinc
dumps the name of the compiled class inMETA-INF/main.kotlin_module
, so we could fetch it from there, but I'm not sure how that would fit in theproblemtools
pipeline.The text was updated successfully, but these errors were encountered: