I’ve got a weird issue with, I think, the kotlin s...
# announcements
b
I’ve got a weird issue with, I think, the kotlin sdk version between intellij and maven. If I run my unit test from intellij (via the run configuration) it runs fine. If I run via maven (both from the command line and via the intelllij maven lifecycle actions) I get a complaint about, effectively, a smart-cast not working. In my pom.xml I have the kotlin version set to 1.3.72 and everywhere in project structure in intelllij seems to agree with that, but it looks like intellij’s is using another version. I would normally just ignore this, but if I try and change my code to not rely on the smart cast, intellij keeps warning me about “unnecessary cast” (and I have -werror enabled, so I can’t build with the warning). Where else can I check for a place where a version might be set incorrectly? I do know that the kotlinc plugin is 1.4.31, but I thought it should still be running “as” 1.3.71 if that’s set everywhere.
Here’s the
Modules
section in
Project Settings
e
it could be new type inference, during version 1.3 the Kotlin plugin turned it on by default while it was still off in the compiler
if unchecking "Preferences » Kotlin Compiler » Enable new type inference algorithm for IDE analysis" makes it stop working in the IDE that's definitely it
b
Hmm I don’t even see that option.
e
oh if your plugin is 1.4 then it's always on
b
image.png
e
you can turn it on in Gradle with something like
Copy code
allprojects {
    tasks.withType<KotlinCompile>().configureEach {
        kotlinOptions {
            freeCompilerArgs += "-XXLanguage:+NewInference"
        }
    }
}
but ideally you just upgrade to 1.4
b
I did previously find that it had 1.4 for language/api version there and changed that, but that didn’t help (and I think those values are supposed to be overridden by the settings from pom.xml anyway)
I’m using maven, but I’ll try adding that arg to enable it
No luck, the maven builds still fail due to not “seeing the smart cast from the contract
I had tried adding
-Xopt-in=kotlin.contracts.ExperimentalContracts
before as well, but no luck.
e
you might just have to rewrite code to be 1.3-compatible without the IDE's help, or upgrade to 1.4. I guess the plugin has too much 1.4 behavior built in that it doesn't accurately act like 1.3
b
Yeah. I originally added a manual “as” line there to make it 1.3 style, but thought intellij warned which broke the build (because of -werror), but I don’t actually have -werror in test-compile so that could work…
Although the IDE flags is as unnecessary, which is annoying