kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

Basic hello world example does not work with interpreter #394

Closed lbenedetto closed 1 year ago

lbenedetto commented 1 year ago
$ kscript --version
Version   : 4.2.1 
Build     : 2023-01-26T16:22:22.430644Z
Kotlin    : 1.8.0-release-345
Java      : JRE 17.0.4+8

$ cat test.kt
#!/usr/bin/env kscript

println("Hello from Kotlin!")
$ ./test.kt
[kscript] [ERROR] Compilation of scriplet failed:
[kscript] [ERROR] Command     : 'bash -c /home/lars/.sdkman/candidates/kotlin/current/bin/kotlinc   -d '/home/lars/.cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/scriplet.jar' '/home/lars/.cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt''
[kscript] [ERROR] Exit Code   : 1   
[kscript] [ERROR] Stdout      : ''
[kscript] [ERROR] Stderr      : '.cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:1: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]^[nl].cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:8: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]       ^[nl].cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:9: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]        ^[nl].cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:10: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]         ^[nl].cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:28: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]                           ^[nl].cache/kscript/jar_dee163c4777cb22e369f1bdaf8ceaf34/Test.kt:4:29: error: expecting a top level declaration[nl]println("Hello from Kotlin!")[nl]                            ^[nl]'
[kscript] [ERROR] 

$ kscript 'println("Hello from Kotlin!")'
Hello from Kotlin!

If I change the script to

#!/usr/bin/env kscript

fun main() {
  println("Hello from Kotlin!")
}

then it works, so I guess this is just an issue with the documentation

lbenedetto commented 1 year ago

Ah, I missed this line in the documentation:

The Githubissues.

  • Githubissues is a development platform for aggregating issues.