https://kotlinlang.org logo
Join Slack
Powered by
# compiler
  • o

    Ousc

    08/23/2025, 3:42 PM
    https://github.com/JetBrains/kotlin/blob/master/docs/backend/IR_parameter_api_migration.md The migration of compiler plugins is too difficult. We have made extensive use of these now deprecated apis, which is very painful. It can already be predicted that after the migration work is completed, a large amount of testing work still needs to be carried out to ensure that they can still function normally.
    c
    z
    • 3
    • 5
  • o

    Ousc

    08/23/2025, 6:13 PM
    In kotlin 2.2.0, dispatchReceiverParameter set () is marked as deprecated And it prompts to directly operate on parameters. But parameters itself is an immutable list, and _parameters is private. Does this mean that I have to copy the entire list, then assigned to the parameters to achieve the goal of modified dispatchRevieverParameter?
    👌 2
    j
    • 2
    • 2
  • z

    Zac Sweers

    08/24/2025, 9:25 PM
    When reporting errors with
    IrDiagnosticReporter
    on declarations that originate from Java, it seems there's never a file present. Is this a bug or should we check for this and report it to
    MessageCollector
    instead? This is with 2.2.20-RC
    d
    • 2
    • 4
  • o

    Oliver.O

    08/25/2025, 12:55 PM
    Can I suppress a klib resover warning like this one to make a build with "-Werror" succeed?
    KLIB resolver: The same 'unique_name=kotlin-stdlib-common' found in more than one library: .../testBalloon/testBalloon-framework-core/build/kotlinTransformedMetadataLibraries/commonMain/org.jetbrains.kotlin-kotlin-stdlib-2.2.20-RC-commonMain-Y8sbrw.klib, .../testBalloon/testBalloon-framework-core/build/kotlinTransformedMetadataLibraries/nonJvmMain/org.jetbrains.kotlin-kotlin-stdlib-2.2.20-RC-commonNonJvmMain-Y8sbrw.klib
    d
    • 2
    • 1
  • z

    Zac Sweers

    08/26/2025, 4:28 AM
    I've got an interesting bug report (with a repro) that comes from kotlinc's IC in a specific path • A KSP processor generates a declaration in its KspTask • The KotlinCompile task compiles this declaration, my compiler plugin (Metro) processes it and generates nested class declarations in FIR • A subsequent incremental compilation reports
    The following LookupSymbols are not yet converted to ProgramSymbols
    for those symbols @ralf filed a detailed report and repro link here. It seems to come from this line, and I wonder if there is another edge case that may need to be carved out above it? I'm not sure how to debug this as attaching a debugger/running the compiler in process disables IC 😕
    👀 1
    d
    o
    • 3
    • 7
  • w

    Willem Veelenturf

    08/27/2025, 6:19 AM
    I'm progressing in building a compiler plugin. Im looking for tools to debug and test my work. Find it hard to debug en get an overview of the tree. What are best practices to write unit tests with as input a sample Kotlin file? Is it possible to run the compiler and place a breakpoint to inspect the output?
    👌 1
    h
    m
    j
    • 4
    • 16
  • j

    Jonas

    08/27/2025, 7:34 AM
    We are currently on a path to automatically fill the current file name in our logger tags with a compiler plugin (similar to this). I now had an idea which I want to validate if the concept would even work. Yesterday after getting our compiler plugin to work I watched a

    video▾

    which in the end references metro for dependency injection. My idea was to combine the usage of metro with cite to first inject the logger (with
    __FILE__
    as tag) and cite replaces this afterwards with the file where it was injected.
    To use both metro and cite simultaneously in a project works fine, but it seems like cite runs first as I always get the file where I declare the dependency not where I use it. Even if I list cite after metro in the plugins configuration. An explicit ordering of compiler plugins is planned with version 2.3.0, would this solve this use case or do I have a conceptual issue here? cc.: @Zac Sweers @jw Thanks in advance for your input.
    j
    z
    j
    • 4
    • 6
  • s

    Scott Sosna

    08/27/2025, 4:41 PM
    I believe - but am struggling to confirm - that the minimum JDK version to run the Kotlin 2.2 compiler remains JDK8? I found one vague reference suggesting it had been changed to JDK17 but otherwise mostly see JDK8. Can someone confirm?
    w
    • 2
    • 9
  • c

    Curtis Kroetsch

    08/27/2025, 8:25 PM
    Hey I am working on a compiler plugin, using kotlin 2.2.20-Beta2 . I got it running in the IDE, but it looks like the version of kotlin-compiler-embeddable used by the IDE is older than this, since it logs failures around recent changes to some compiler classes like:
    Copy code
    org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol: method 'void <init>()' not found
    Is there a way to control the version the IDE and match what version my plugin is using? Or any other way to develop on a newer version?
    y
    h
    • 3
    • 2
  • t

    theapache64

    08/29/2025, 5:54 AM
    Hey folks, Given that Kotlin/JS compilation follows the pipeline:
    Kotlin Code → Kotlin IR → Kotlin/JS Compiler → JavaScript
    does this mean I could theoretically create a Kotlin/C++ compiler (or is it called transpiler?) by building a new backend that transforms Kotlin IR into C++ code, similar to how the existing Kotlin/JS backend transforms IR into JavaScript? 🤔 thanks in advance 🙌
    🍀 1
    y
    d
    t
    • 4
    • 30
  • m

    Michael Paus

    08/30/2025, 4:41 PM
    This is more of a theoretical question and I am not sure whether it actually belongs into this channel but I just give it a try. I’d like to know whether it is theoretically possible to automatically transpile any valid Java program into an equally valid Kotlin program for the JVM while ensuring 100% compatibility with the original Java code.
    j
    • 2
    • 1
  • w

    Willem Veelenturf

    08/31/2025, 8:12 AM
    Hi channel, with some help #Junie I finished my first Kotlin compiler plugin. The plugin does automatic ad-hoc data mapping. You only have to specify fields that do not match. I would like to ask for feedback and some advice if it makes sense to keep maintaining this plugin regarding the current state of compiler plugins and the advice not creating them. @mbonnin thanks for helping out with the test setup https://github.com/flock-community/kmapper
    ❤️ 1
    p
    • 2
    • 2
  • a

    Andrey

    09/01/2025, 7:05 AM
    Hello everyone, can anyone tell me if it is possible to force the compiler not to generate strings like "`.data.rel.ro:0000000000320012 0000002E C (16 bits) auth$1$invoke$$inlined$`" ? Even if I
    strip
    functions with such lines it is very easy to restore and reverse the code. Any ideas?
  • m

    Mohammad Fallah

    09/01/2025, 2:15 PM
    Weeks ago, I came up with an idea for a simple Kotlin compiler plugin to solve the prop-drilling problem in Compose. In practice, many of our composable functions are private and usually called only once, often just to wrap something in a
    Box
    or similar. But this forces us to pass parameters down through three or four functions. The result is unnecessarily bloated function signatures. The real pain comes when you need to add a new parameter to the deepest composable — you end up modifying five or six functions just to thread that value all the way down. My idea was to annotate the child’s parameter with
    @arg
    . A class would then be generated for that function’s arguments, which you could reference in its parent. The class would act only as a marker and get replaced by the actual parameter at compile time. (I’ve attached an image to illustrate this.) Unfortunately, I gave up on the implementation. The compiler plugin API is poorly documented, and the solution felt fragile — I worried it might easily break with the next Kotlin release. So, I decided to share the concept instead. Maybe someone in the community with deeper knowledge of compiler internals can pick it up and turn it into something stable. (it's not the whole solution and there are more that I'll share if someone is interested)
    e
    t
    +2
    • 5
    • 13
  • t

    theapache64

    09/03/2025, 10:16 AM
    how can i share a common module with my gradle-plugin module and compiler-plugin module… since i’ve a composite build structure, the usual way of adding
    implementation(project(":common"))
    in gradle-plugin doesn’t seem to be working.. 🤔 am i missing something or doing it wrong…
    m
    • 2
    • 7
  • z

    Zac Sweers

    09/03/2025, 2:40 PM
    I'm seeing some interesting behavior where KSP-generated sources in
    iosSimulatorArm64Main
    are not visible in FIR during
    iosMain
    compilation but are visible during IR. Is there a way to force compilation on a more specific set of inputs to see them in FIR? Or perhaps I'm misunderstanding how this part of the pipeline works
    y
    d
    • 3
    • 11
  • a

    Alexander Ioffe

    09/03/2025, 6:38 PM
    Does IrFunction have a stable unique-identifier that survives compilation (ie that would be the same whether the parent is a IrFile or an IrExternalPackageFragment)?
    y
    z
    • 3
    • 5
  • p

    phldavies

    09/03/2025, 10:15 PM
    Would it be feasible to create a compiler plugin that can lift a parameter (or context-parameter) as an additional receive within the scope of a function. An example would be to have something like
    Copy code
    context(@Receiver _: MyScope) fun doSomething() { callSomething() }
    be translated to
    Copy code
    context(_: MyScope) fun doSomething { with(contextOf<MyScope>()) { callSomething() } }
    My gut says no but this would be a nice way of avoiding the need to create context parameter bridge functions.
    y
    • 2
    • 1
  • w

    Willem Veelenturf

    09/04/2025, 10:10 AM
    Quick question it possible to package a compiler-plugin as maven-plugin ?
  • d

    Drew Hamilton

    09/04/2025, 3:38 PM
    When I bump Poko to 2.2.20-RC2 and try to use it with a project building with 2.2.0, JS compilation fails because it appears to find multiple functions named
    js.toLong
    . (Stacktrace etc. in thread.) I haven’t seen an error like this before; is this an expected incompatibility?
    d
    • 2
    • 5
  • m

    mbonnin

    09/04/2025, 4:00 PM
    Can I match the IDE version of Kotlin to a Kotlin release somewhere? My IDE says it's using
    build-2.2.20-ij252-17
    . Can I find this released somewhere so I have the same version in my plugin and IDE?
    d
    d
    • 3
    • 3
  • m

    mbonnin

    09/04/2025, 4:03 PM
    Related question: are there resources/best practices about debugging IDE behaviour? I have issues in the IDE (red underlines) that are OK during a build. I think that's understandable given the paths are different but I find this a lot harder to debug. Can I set breakpoints in the IDE while running/log statements?
    d
    • 2
    • 2
  • s

    segunfamisa

    09/06/2025, 12:10 PM
    Hey folks, TL;DR: I want to modify kotlin source in-place but it's proving difficult using kotlin compiler tools. -- I'm trying to create a mutation of a
    kt
    file/code, such that the rest of the content remains the same, and only specific mutations that I want to add get processed. I want to update the code in-place, as a form of auto-correction, I would like this to happen using the Psi visitor. I have tried using compiler embeddable & a PsiFactory to create an expression, and then call
    expression.replace()
    . in my
    visit*()
    function. The code breaks in runtime with:
    Copy code
    Missing extension point: org.jetbrains.kotlin.com.intellij.treeCopyHandler in container {}
    I've seen comments about that error, and the seem to imply that the PSI tree is immutable, so I can't modify it (perhaps because I'm not in the IDE context). My ideal case would be to run this piece of code, define the mutation I want to apply, and a target kotlin file, and it modifies the file in-place. -- Is there any advise on how to approach this?
    • 1
    • 1
  • e

    Eugen Martynov

    09/08/2025, 3:58 PM
    Is there possibility with dsl construct copy. Something like
    Copy code
    data class Wrapper(
       val data: String = "Test",
       val intData: Int = 5
    )
    
    fun wrapper(copy: Wrapper.() -> Wrapper) {
      Wrapper().copy(....)
    }
    
    val wrapper = wrapper { data = "Another" } // Constructs Wrapper("Another", 5)
    d
    y
    • 3
    • 28
  • m

    madisp

    09/11/2025, 8:16 AM
    hello, started getting
    VerifyError
    at runtime after bumping to Kotlin 2.2.20. Happens with 2.2.10 as well, 2.2.0 is ok. 100% reproducible. The JVM error for this dumps bytecode, is there some other channel than Youtrack for reporting this? I'd be happy to share offending source / compiled bytecode privately.
    d
    • 2
    • 3
  • w

    wasyl

    09/12/2025, 1:31 AM
    If a compiler plugin defines its own warnings, should I expect to be able to
    "-Xwarning-level=<custom_warning>:error"
    them? Specifically I'm trying to raise the `SUGGEST_CLASS_INJECTION` inspection level to
    error
    but I get an
    e: Warning with name "SUGGEST_CLASS_INJECTION" does not exist
    error, even if I only add the compiler warning when the plugin is applied:
    Copy code
    plugins {
      id 'dev.zacsweers.metro'
    }
    
    tasks.withType(KotlinCompile).configureEach {
      compilerOptions.freeCompilerArgs.addAll(
        "-Xwarning-level=SUGGEST_CLASS_INJECTION:error",
      )
    }
    this happens for
    :compileKotlin
    tasks in jvm modules. Is it an issue with the compiler plugin or Kotlin? Or my setup?
    d
    z
    • 3
    • 3
  • x

    Xavier F. Gouchet

    09/12/2025, 6:45 AM
    Hi, I updated a compiler plugin to Kotlin 2.2.O and saw that the `FirExpressionChecker`'s
    check
    method is marked as Deprecated, but I can't see any info on what is recommend to use instead. Is there an official suggestion to get the same effect in a
    FirAdditionalCheckersExtension
    ?
    d
    • 2
    • 2
  • a

    Alexander Ioffe

    09/16/2025, 4:54 AM
    Do backend-IR lambdas need to be declared differently in Kotlin 2.2.20? I getting platform-declaration-clash errors e.g:
    Copy code
    Platform declaration clash: The following declarations have the same JVM signature (xrSqlQueryModelTokenImpl$lambda$0$0(Lio/exoquery/SqliteDialect;Lio/exoquery/sql/SqlQueryModel;)Lio/exoquery/sql/Token;):
        fun `xrSqlQueryModelTokenImpl$lambda$0$0`(`this$0`: SqliteDialect, `$this_with`: SqlQueryModel): Token defined in io.exoquery.SqliteDialect
        fun `xrSqlQueryModelTokenImpl$lambda$0$0`(`this$0`: SqliteDialect, `$this_with`: SqlQueryModel): Token defined in io.exoquery.SqliteDialect
    This goes away when in my
    buildFun
    call I replace
    IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
    with
    IrDeclarationOrigin.LOCAL_FUNCTION
    . Have the lambda-naming rules changed in 2.2.20?
    • 1
    • 1
  • f

    François

    09/16/2025, 6:44 PM
    Hi, there is something new with the version of Swift embedded by Xcode 26, used by cinterop. The modulemap needed by cinterop has moved inside another folder (a new include folder instead of the root folder). The required -fmodules flag doesn’t work, it doesn’t found the expected module anymore. I’m looking inside the llvm documentation about fmodules customization, but I don’t know if it’s working (FYI: kotlin 2.2.20 or ealier)
    d
    s
    • 3
    • 13
  • t

    tjohnn

    09/17/2025, 10:43 PM
    Hi there, as all the factory functions for
    KotlinCoreEnvironment
    are now marked deprecated in the latest
    kotlin-compiler-embeddable
    and are to be removed from version 2.3+, is it safe to assume the reworked alternative will be available in version 2.3 or we should look for some other alternatives 😄?
    h
    d
    • 3
    • 10