Little disappointed that this issue is not resolve for M4
http://youtrack.jetbrains.com/issue/KT-3045
It a useful great tool to let beginner to play with Kotlin. Not sure why priority is not in it. Shipping a broken “-script” option is not a good thing to let people to see, especially if they first time playing with it. If not ready, I would even recommend not to show it in help page.
Zemian
The -script option doesn't seem to be broken. This works fine for me:
``
bin/kotlinc-jvm -script foo.ktscript
The exception in the report is a bad diagnostics on broke command line syntax, no more than that.
HI Andrey,
I tried with M4 and it’s still now working for me. Is there something I am doing wrong?
bash> bin/kotlinc-jvm -script Test.kt
EXCEPTION: java.lang.RuntimeException: Failed to evaluate script: java.lang.NullPointerException
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileScript(KotlinToJVMBytecodeCompiler.java
:265)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileAndExecuteScript(KotlinToJVMBytecodeCom
piler.java:229)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:139)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:54)
at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:117)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:181)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:54)
at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:47)
at org.jetbrains.jet.cli.common.CLICompiler.doMainNoExit(CLICompiler.java:160)
at org.jetbrains.jet.cli.common.CLICompiler.doMain(CLICompiler.java:151)
at org.jetbrains.jet.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.java:58)
Caused by: java.lang.NullPointerException
at org.jetbrains.jet.lang.resolve.ScriptNameUtil.classNameForScript(ScriptNameUtil.java:40)
at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileScript(KotlinToJVMBytecodeCompiler.java
:262)
... 10 more
exec() finished with INTERNAL_ERROR return code
bash> bin/kotlinc-jvm -version
INFO: Kotlin Compiler version 0.4.297
Changing the file extension to .ktscript should help
Ah ha! Now that's a tricky requirement. Perhaps it should be a hint on the -help page? I would never guess that out.
Thanks Andrey. I will try out more on this -script feature now that I get it to work. 