New Type Inference in Kotlin 1.3.0-rc-190

Hi,
according to that video KotlinConf 2018 - New Type Inference and Related Language Features by Svetlana Isakova - YouTube i would like to try New Type Inference.

But i can not activate it :frowning:
Preconditions:

Android Studio 3.3 Canary 13
Build #AI-182.4505.22.33.5035453, built on September 28, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14
Gradle 4.10.2 with Kotlin DSL
Kotlin “gradle-plugin” version 1.3.0-rc-190
Kotlin “stdlib-jdk7” version 1.3.0-rc-190

The only available experimental option is “coroutines”.
Please advice! Thank you in advance!

adding following options to the gradle script will fix the issue:

afterEvaluate {
    tasks.withType(KotlinCompile::class)
        .forEach {
            it.kotlinOptions { freeCompilerArgs = listOf("-Xnew-inference") }
        }
}

This has been answered in Slack Slack but I’ll repeat the answer for others here:

This flag hasn’t landed in the compiler yet. You have to use the old -X flags for now.

Groovy DSL:

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-XXLanguage:+NewInference"]
    }
}

Kotlin DSL:

tasks.withType(KotlinCompile::class)
        .forEach {
            it.kotlinOptions { freeCompilerArgs = listOf("-Xnew-inference") }
        }
1 Like

Why Kotlin DSL and Grovvy flags are different? doesn’t looks as right snippet, probably only one is correct: Groovy DSL flag is correct, so Kotlin DSL should be:

tasks.withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs += "-XXLanguage:+NewInference"
        }
    }

I also add compiler flags instead of replacing existing ones and use Kotlin DSL API with reified generics to make snippet more Kotlin DSL friendly

1 Like

What’s the proper way to enable it with Kotlin multiplatform plugin and languageSettings in the Gradle DSL?

Note that I’m using Gradle Kotlin DSL, but I don’t think it’s different when used with Groovy for the new MPP plugin.

Answering my own question:

enableLanguageFeature("NewInference")

In a build.gradle.kts file, it looks like this:

kotlin {
    ...
    sourceSets {
        all {
            languageSettings.apply {
                enableLanguageFeature("NewInference")
            }
        }
        ...
    }
    ...
}