https://kotlinlang.org logo
#eap
Title
# eap
j

Jeff Lockhart

10/13/2023, 5:53 PM
What's the proper way to pass the
-Xexpect-actual-classes
flag to the compiler in 1.9.20-RC? Previously in 1.9.20-Beta2 I had:
Copy code
kotlin {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
But this top-level
compilerOptions
has been removed now. I've tried
Copy code
tasks.withType<KotlinCompile>().configureEach {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
and
Copy code
tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs += "-Xexpect-actual-classes"
    }
}
but still get the warning
'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. You can use -Xexpect-actual-classes flag to suppress this warning. Also see: https://youtrack.jetbrains.com/issue/KT-61573
during compilation.
Also doesn't work:
Copy code
tasks.withType<KotlinCompilationTask<*>>().configureEach {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
a

Alexander.Likhachev

10/13/2023, 6:16 PM
Indeed, we decided to take more time to polish the top-level
compilerOptions
and it’s now postponed until 2.0 Please try using
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.add("-Xexpect-actual-classes")
            }
        }
    }
}
j

Jeff Lockhart

10/13/2023, 6:46 PM
Thanks, this looks to work. What's the reason the other mechanisms to pass
freeCompilerArgs
don't work?
a

Alexander.Likhachev

10/13/2023, 10:53 PM
Did you see compilation errors (from Gradle) or red code in IDEA?
j

Jeff Lockhart

10/13/2023, 11:08 PM
I see both Gradle compilation warnings and warnings in the IDE (not errors or red code, just warnings) using the mechanisms I tried. Both warnings go away with your method.
a

Arkadii Ivanov

11/02/2023, 9:26 PM
How can I fix it with Groovy Gradle and Kotlin 1.9.20?
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.add("-Xexpect-actual-classes")
            }
        }
    }
}
Gives:
Copy code
> Ambiguous method overloading for method org.jetbrains.kotlin.gradle.targets.native.NativeCompilerOptions#configure.
  Cannot resolve which method to invoke for [class build_a61yfy2uoq4qbs0ma6w75b74a$_run_closure2$_closure4$_closure7$_closure8] due to overlapping prototypes between:
  	[interface kotlin.jvm.functions.Function1]
  	[interface org.gradle.api.Action]
This seems working.
Copy code
kotlin {
    targets.configureEach {
        compilations.configureEach {
            compilerOptions.configure((Action) { it.freeCompilerArgs.add("-Xexpect-actual-classes") })
        }
    }
}
e

elect

11/08/2023, 10:01 AM
is this supposed to work in KMP as well? Because for my generated code it doesnt look working..
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.addAll("-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn", "-Xexpect-actual-classes")
            }
        }
    }
}
a

Arkadii Ivanov

11/08/2023, 10:07 AM
Yep, the expect/actual flag works for me with KMP. I replaced
all
with
configureEach
, though.
e

elect

11/08/2023, 10:09 AM
Copy code
targets.configureEach {
    compilations.configureEach {
        compilerOptions.configure {
            freeCompilerArgs.addAll("-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn", "-Xexpect-actual-classes")
        }
    }
}
same results
and this
(Action) { it.freeCompilerArgs
doesn't even compile (kts)
a

Arkadii Ivanov

11/08/2023, 10:24 AM
The thing with Action was needed for Groovy. For Kts the last code I posted works for me.
31 Views