Olaf Gottschalk
03/24/2023, 6:21 PMinfix fun <T> String.blah(processor: (String)->T): T
infix fun <T> String?.blah(processor: (String)->T): T?
Normally, such problems can be fixed by adding a specific @JvmName
annotation to at least one of the two methods - but in this case you get an error, stating "'@JvmName' annotation is not applicable to this declaration". This is quite a downer.. why is that and how can I make this compile? I thought an extension function is nothing special at all, in my case a function with two arguments...
Any chance I might get this working? Thanks!rrva
03/26/2023, 3:54 PM@OptIn(ExperimentalCompilerApi::class)
@AutoService(CompilerPluginRegistrar::class)
class MyPlugin : CompilerPluginRegistrar() {
override val supportsK2: Boolean
get() = true
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
messageCollector.report(
CompilerMessageSeverity.WARNING,
"*** Hello from MyPlugin ***"
)
}
}
in the project which uses the plugin, I have defined
tasks.withType<KotlinCompile> {
kotlin {
jvmToolchain(19)
kotlinOptions {
verbose = true
useK2 = false
}
}
}
and when running ./gradlew --debug
i can grep for KOTLIN in the logs and see some of the compiler output, where my plugin is mentioned:
2023-03-26T12:50:40.339+0200 [DEBUG] [org.gradle.api.Project] [KOTLIN] Subplugin my-plugin loaded
2023-03-26T12:50:40.339+0200 [DEBUG] [org.gradle.api.Project] [KOTLIN] Loading subplugin my-plugin
2023-03-26T12:50:40.339+0200 [DEBUG] [org.gradle.api.Project] [KOTLIN] Adding 'se.rrva:my-plugin:1.0.5' to 'kotlinCompilerPluginClasspathTest' configuration
Slackbot
03/26/2023, 9:24 PMLars Frost
03/27/2023, 9:48 AMgroostav
03/27/2023, 7:25 PMval firstDbl: Double = 0.1
val firstStr: String = "0.1"
val firstBigStr = BigDecimal("0.1")
val firstBigDbl = BigDecimal(0.1)
has some funny equality implications:
firstDbl == firstStr.toDouble() //true
firstBigStr == firstBigDbl //false
firstBigStr.toDouble() == firstBigDbl.toDouble() // false, 0.1 != 0.0...555
firstBigDb.toString() // 0.1000000000000000055511151231257827021181583404541015625
Can somebody help me understand where this error came from? Should i be calling a different BigDecimal constructor?natario1
04/01/2023, 3:59 PMinterface Bindable<in T> {
fun bind(input: T)
fun unbind()
}
And I’m trying to define two utility functions, one when T is nullable, one when it is not:
inline fun <B : Bindable<T>, T: Any> B.use(input: T, block: B.() -> Unit) {
bind(input); try { block() } finally { unbind() }
}
inline fun <B : Bindable<T?>, T: Any> B.use(input: T? = null, block: B.() -> Unit) {
bind(input); try { block() } finally { unbind() }
}
The only difference being that, in case of nullable T
I can provide a default value to input. The problem is that the compiler complains about resolution ambiguity at use site in some cases, I think due to the in
modifier. Is there any mechanism (annotation?) I can use to help it choose?
For example, I’m calling Bindable<Long?>.use(0L) { … }
. I don’t care which one is chosen in this case, source code is the same.Icyrockton
04/08/2023, 12:20 AMlow level
mean in analysis package? e.g. low-level-api-fir
Icyrockton
04/08/2023, 3:13 AMCone
in ConeKotlinType
classDave
04/14/2023, 4:03 PMStrum355
04/17/2023, 7:03 PMDave Leeds
04/17/2023, 7:49 PMkotlinOptions.allWarningsAsErrors = true
but wondering if there's a way to pick individual warnings to regard as errors.mcpiroman
04/18/2023, 2:03 PMIcyrockton
04/20/2023, 7:48 AMlouiscad
04/20/2023, 10:40 AMb()
produces more complex bytecode than a()
, instead of just adding a private field to the anonymous class?
fun interface Counter {
fun getAndIncrement(): Int
}
fun a(): Counter = object : Counter {
var number = 42
override fun getAndIncrement(): Int {
return number++
}
}
fun b(): Counter {
var number = 42
return Counter { number++ }
}
Olaf Gottschalk
04/20/2023, 3:59 PMAshish Suman
04/20/2023, 7:22 PMwasyl
04/24/2023, 5:12 PM-Xreport-perf
(with and without kotlin.compiler.execution.strategy=in-process
) but I see no output anywhere, and I couldn't find any documentation outlining what flags exists and how they should work. I also tried kotlin.build.report.output=file
but I don't think it provides the information I want (and it doesn't work anyway, always produces an empty file)jw
04/25/2023, 2:18 PMLukasz Mlynik
05/03/2023, 6:21 AMStrum355
05/04/2023, 8:14 PM> Task :app:compileKotlin FAILED
e: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/resolve/jvm/extensions/AnalysisHandlerExtension$DefaultImpls
at com.sourcegraph.semanticdb_kotlinc.Analyzer.doAnalysis(Analyzer.kt:24)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:123)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
Alexander Ioffe
05/05/2023, 8:34 AMTóth István Zoltán
05/07/2023, 12:50 PMHannes Korte
05/09/2023, 11:32 AM// This code compiles, but leads to an NPE on a non-nullable type
class Foo {
val output = doSomething()
val input = "This value is not set yet"
fun doSomething(): String = input.uppercase()
}
The order of the class properties matters, as input
is still null
, when doSomething()
is called. This is trivial to see in this example, but tricky in more complex scenarios. Is this expected behavior? Couldn't the compiler notice the nullability issue?Tóth István Zoltán
05/10/2023, 10:16 AMpluginContext.createDiagnosticReporter(_PLUGIN_ID_)
to create a diagnostics reporter and send the errors through that reporter.
Is there a smarter way to do this? It is an inconvenience only but I don't like that the build seems like an error even when it is successful.PixelHamster
05/10/2023, 9:27 PMgradle build
but intellij says it can't build the project:
/home/merlijn/.gradle/caches/modules-2/files-2.1/com.google.devtools.ksp/symbol-processing-gradle-plugin/1.8.21-1.0.11/84f788fcf1cbc31bb6491f29df3343c8b5fcc7c1/symbol-processing-gradle-plugin-1.8.21-1.0.11.jar!/META-INF/gradle-plugin.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
This happened when I wanted to update from 1.6 compiler to 1.8 along with kotlin 1.7.20 libs to 1.8.20jw
05/11/2023, 7:00 PMconfigureJdkClasspathRoots()
but it no-ops when the JDK is Java 9+, presumably due to the switch to modules and the disappearance of rt.jar
. It seems like there's helpers for adding module roots given I know the path. Is it just my responsibility to do the JDK lookup, check for modular, and then conditionally do one or the other?mcpiroman
05/16/2023, 12:19 PMWaldemar Kornewald
05/16/2023, 12:41 PMinline
can’t always be used to work around it.Piotr Krzemiński
05/18/2023, 12:40 PMDrew Hamilton
05/19/2023, 11:08 PMirCall
, like how data classes have generated calls to their properties’ hashCode functions. Is it possible to generate a call to an arbitrary function that you don’t have a direct reference to, like a kotlin-stdlib-common
function?