JetBrains / kotlin-compiler-server

Server for executing kotlin code
Apache License 2.0
248 stars 73 forks source link

fix JS example in README #714

Closed RaphaelTarita closed 9 months ago

RaphaelTarita commented 9 months ago

Currently, the example for "Translate Kotlin code to JavaScript code" sends the following Kotlin code to the compiler server:

fun main() {
    println(args[0])
}

This is invalid Kotlin code (atleast in 1.9.20) because args is an unresolved reference. The compiler server will return the following response:

{
    "jsCode": null,
    "exception": null,
    "errors": {
        "File.kt": [
            {
                "interval": {
                    "start": {
                        "line": 1,
                        "ch": 12
                    },
                    "end": {
                        "line": 1,
                        "ch": 16
                    }
                },
                "message": "Unresolved reference: args",
                "severity": "ERROR",
                "className": "ERROR"
            }
        ]
    },
    "text": ""
}

I fixed it by changing the sent Kotlin code to:

fun main(args: Array<String>) {
    println(args[0])
}

The updated example will work as expected with the compiler server.

zoobestik commented 9 months ago

Thanks! 🙏