Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
222 stars 47 forks source link

missing ExperimentalStdlibApi annotations cause compilation failures with Kotlin 1.9.x compiler #136

Closed atsushieno closed 8 months ago

atsushieno commented 8 months ago

Currently antlr-kotlin code generator emits code like this:

    override val ruleNames: Array<String> =
        Rules.entries.map(Rules::name).toTypedArray()

    override val channelNames: Array<String> =
        Channels.entries.map(Channels::name).toTypedArray()

    override val modeNames: Array<String> =
        Modes.entries.map(Modes::name).toTypedArray()

They result in compilation error when we use Kotlin 1.9.x compiler, like:

e: file:///Users/atsushi/sources/KtMidi/mugene-ng/mugene-project/mugene/build/generatedAntlr/dev/atsushieno/mugene/parser/MugeneLexer.kt:128:15 This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'

Enum.entries seems part of experimental API in Kotlin 1.9.x, according to the Kotlin documentation:

The enumEntries() function is Experimental. To use it, opt in with @OptIn(ExperimentalStdlibApi), and set the language version to at least 1.9.

I have a fix for this, will create a PR.

Confirmed with 82ded4f

ftomassetti commented 8 months ago

Fixed via #137