https://kotlinlang.org logo
Join SlackCommunities
Powered by
# compiler
  • p

    PHondogo

    04/15/2025, 8:02 AM
    Copy code
    if (e is Error
        && e !is AssertionError
        && e !is NotImplementedError // why compiler complains about "Check for instance is always 'true'." ?
    ) {
        throw e
    }
    d
    • 2
    • 13
  • a

    Alexander Ioffe

    04/16/2025, 2:14 AM
    Hi, any chance a kind JetBrains dev could help me out? I'm getting an odd error when I do:
    Copy code
    val getterSymbol = cls.getPropertyGetter(propertyName)
    with (builder) {
      irCall(getterSymbol).apply {
        dispatchReceiver = parent
      }
    }
    The error is:
    Copy code
    Caused by: java.lang.IllegalStateException: IrFieldSymbolImpl is unbound. Signature: null
    	... 285 more
    Strange thing is, it only happens when I do something like this:
    Copy code
    doSomething {
      val myClassInst = MyClass(myProperty = "foobar")
      doSomethingElse {
        callToTransform(myClassInst)
      }
    }
    When the variables are lined up together like so:
    Copy code
    doSomething {
      doSomethingElse {
        val myClassInst = MyClass(myProperty = "foobar")
        callToTransform(myClassInst)
      }
    }
    Then it's fine. What am I missing here? Why does one situation work and not the other?
    d
    • 2
    • 1
  • r

    Roman Rastiehaiev

    04/16/2025, 10:58 PM
    Hi folks! I'm playing with kotlin compiler plugin. I do a simple job: in original class I generate nested helper class and member function that returns instance of this nested class.. I've managed to implement both FE and BE, and everything works when I run the code. However, IDE doesn't "see" the generated method I take
    kotlin-serialization
    plugin as example for implementing my plugin but I couldn't find the code that "introduces" generated class & method to IDE. Could someone please point me to the place where to look?
    e
    • 2
    • 3
  • j

    Joel Wilcox

    04/17/2025, 1:30 AM
    šŸ‘‹ I have the following situation: Given
    Copy code
    @ContributesBinding(AppScope::class)
    @ContributesBinding(AltScope::class)
    @Inject
    class ContributingClass : SomeInterface
    I generate some nested classes in a
    FirDeclarationGenerationExtension
    where we end up with
    Copy code
    @ContributesBinding(AppScope::class)
    @ContributesBinding(AltScope::class)
    @Inject
    class ContributingClass : SomeInterface {
    
      @Contribution(AppScope::class)
      class NestedContribution
    
      @Contribution(AltScope::class)
      class NestedContribution2
    }
    After ``FirDeclarationGenerationExtension#generateNestedClassLikeDeclaration` has run and generated both classes, we get to
    FirSupertypeGenerationExtension#computeAdditionalSupertypes
    and I try to query for the nested classes but I'm not able to find them. Things I've tried include •
    session.predicateBasedProvider.getSymbolsByPredicate(parentAnnotated(contributesBinding))
    - this finds `ContributingClass`'s constructor •
    session.predicateBasedProvider.getSymbolsByPredicate(annotated(contribution))
    - this finds nothing • Accessing `ContributingClass`'s
    declarationSymbols
    -- this finds the constructor Is it possible to access the nested generated classes here? Based on some older discussions I was thinking this should be possible so I'm not sure if perhaps I'm setting something up incorrectly, or that the generated nested classes are just not accessible yet at this phase. Additional notes: • I have all the predicates registered in the
    FirSupertypeGenerationExtension
    • Right now this is for all code living in the same module/compilation
    d
    • 2
    • 2
  • d

    dhkim

    04/17/2025, 8:01 AM
    Hi, the system I'm currently working on generates a set of Kotlin source codes on the fly and compiles them using K2 compiler. It's done at runtime and it's important to keep the whole time required from the source code generation to compilation minimal. In the light of minimizing the time, I'm about to explore uses of FIR plugins. If I generate FIR in my plugin instead of the comparable source code, how much time can be slashed? Like what percent of ANALYZE metric obtained from compiler performance report. Just a ball park figure would be appreciated.
    d
    s
    • 3
    • 28
  • f

    Fudge

    04/17/2025, 8:18 PM
    Are there any updates about a stable compiler plugin API? This issue was not updated since 2023: https://youtrack.jetbrains.com/issue/KT-49508/Stabilize-the-K2-Compiler-Plugin-API
    e
    • 2
    • 1
  • r

    Raid Xu

    04/18/2025, 5:52 AM
    Hi, has anyone checked this issue KT-76805 Wrong NPE occurs when assigning synthetic properties with platform types in Kotlin 2.1.20 ? It's causing a crash for us (and potentially many other people) so we have to fallback to 2.1.10.
  • x

    Ximing Chen

    04/18/2025, 4:05 PM
    Hello, I want to know if the Kotlin team has a compatibility roadmap for AGP? As we know, AGP 8 completely removed the Transform API, but in my team, because some plug-in use cases cannot be implemented in AGP 8, the large number of API changes to upgrade AGP are also quite difficult to adapt, causing us to be stuck in the AGP 7 version (currently 7.0, we will try to migrate to 7.4). If Kotlin stops supporting AGP 7 compatibility, upgrading to a new version of Kotlin will become more difficult.😢
    m
    p
    e
    • 4
    • 11
  • a

    Amadey

    04/21/2025, 8:01 AM
    Hi guys! I am in the process of creation of my own compiler plugin, hope it's the right place to ask My current issue is that I am trying to make all FIR generation, as well as FIR diagnostics run without the need to build, or compile my project I've seen similar behavior while working with the kopy plugin, but I am not able to replicate this behavior, nor was I able to contact the author, unfortunately Things that I have tried already: • explicitelly using FIR option, on pre-K2 compilers • migrating to K2 and enabling it in my IDE, plus unchecking only.bundled.plugins option • mentioning my plugin in -XPlugin argument But as I said, it all leads to my plugin actually generating code after project's compilation start May be somebody can help me highlight what am I doing wrong?
    y
    h
    j
    • 4
    • 13
  • j

    Joel Wilcox

    04/22/2025, 1:21 AM
    I'm working on a bug fix in Metro (https://github.com/ZacSweers/metro/pull/343/files) where everything works as expected when there's a single compilation, but am running into some interesting annotation argument behavior when I test the same setup using two modules/compilations. I have this object definition
    Copy code
    @ContributesBinding(AppScope::class, binding = binding<ContributedInterface>())
              object Impl1 : ContributedInterface, OtherInterface
    where I want to evaluate the
    binding
    argument of
    ContributesBinding
    inside a
    FirSupertypeGenerationExtension
    . When the above snippet is defined with the rest of my code in a single module, the
    binding
    arg is accessible as a
    FirFunctionCall
    which allows me to get its parameterized type
    ContributedInterface
    . Once I move the
    Impl1
    snippet to a separate module and compilation, the
    FirSupertypeGenerationExtension
    sees the
    binding
    arg as a
    FirAnnotationImpl
    rather than some type of call. This results in the binding arg coming back as null since we're not able to access the parameterized type. Any ideas on additional changes I might need to make to support both use-cases and access the argument as a call-type? Also happy to provide more details if needed
    b
    • 2
    • 4
  • r

    Roman Rastiehaiev

    04/22/2025, 9:46 PM
    Hey folks I'm trying to write kotlin compiler plugin. I published my plugin to gradle portal, and I try to use it in 2 different repos In the first repo it works fine, in the second - no. In the second repository I receive the error when my plugin tries to get a resolved type from method return type The code in those two repos is the same, except in the second one I also use kotlin serialization plugin. I checked - if I disable it, my plugin works fine Does someone know why it may happen and how to fix it?
    v
    j
    +2
    • 5
    • 14
  • t

    thramp

    04/24/2025, 3:34 PM
    Hiya folks! I’m curious about some of K2’s implementation details. For context, I work on rust-analyzer—a language server for the Rust programming language—and we were discussing K2. I had a question about it: how does K2 do invalidations/at what level of granularity does K2 invalidations? As I understand, K2 does resolution on a per-declaration basis, so I’m guessing invalidations are similarly done on a per-declaration basis (as opposed to, say, per-file). For context, in rust-analyzer, we have an extremely fine-grained invalidation scheme powered by a library called Salsa, where we invalidate analysis whenever an item (a function, body, trait definition, etc.—a declaration, in Kotlin’s terminology, I think?)—changes. The mechanism by which we accomplish this invalidation/incrementality is best described in the Rust compiler’s documentation, so even though we’re tracking lots of stuff, we’re able to be minimize how much work we need to redo on a per-edit basis.
    y
    d
    d
    • 4
    • 8
  • e

    eygraber

    04/25/2025, 4:49 PM
    I'm assuming this is coming from something compiler related because of ktlint, please redirect me if I'm wrong. I'm getting this warning when I use Java 24.
    Copy code
    WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
    WARNING: sun.misc.Unsafe::objectFieldOffset has been called by org.jetbrains.kotlin.com.intellij.util.containers.Unsafe (file:/home/eli/workspace/myapp/tmp/ktlint-1.5.0)
    WARNING: Please consider reporting this to the maintainers of class org.jetbrains.kotlin.com.intellij.util.containers.Unsafe
    WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
    e
    • 2
    • 1
  • t

    TwoClocks

    04/27/2025, 7:00 PM
    n00b compiler plugin question: I've done a few KSP annotations, but now I think I need to do a compiler plugin. I want to write a logging library that uses C++'s (rust/zig/python) std::fmt syntax, and moves the data to another process (shared-mem) for the actual logging. So if I write something like
    logDebug("name:{s} id:{d}", name, id)
    I want to generate this function in the compiler plugin.
    c
    y
    +2
    • 5
    • 26
  • y

    Youssef Shoaib [MOD]

    04/30/2025, 2:30 PM
    When implementing
    suspend () -> A
    I'm getting a
    TypeError: this.permutation0__1 is not a function
    on JS. I seem to recall that function subclassing is not possible on JS? Is there an issue tracking this? EDIT: Found it!
    c
    • 2
    • 2
  • o

    Oğuzhan Soykan

    04/30/2025, 3:16 PM
    With
    2.2.0-Beta2
    version bump, I am getting
    Identity-sensitive operation on an instance of value type 'Instant?' may cause unexpected behavior or errors.
    warnings. And I have ā€œAll warnings are errorsā€ configurations enabled, hence the build fails. How can I disable this specific warning? I’ve checked the blog post: https://kotlinlang.org/docs/whatsnew-eap.html but didn’t see specific option to disable those šŸ¤”
    d
    • 2
    • 2
  • s

    suresh

    04/30/2025, 7:12 PM
    After upgrading to
    2.2.0-Beta2
    , compilation fails with the following error
    b
    d
    +3
    • 6
    • 25
  • a

    anlex N

    05/01/2025, 3:15 AM
    Hello, everyone. Whether does jetbrains company use your own JDK to build apache flink, spark, hbase and others? I am using openjdk(jre) to run these projects, but these projects lock me to use jdk 11 version, as you know, oracle have deprecated jdk 11 version for a long time. Have you tried to use recent version for producion use?
    not kotlin but kotlin colored 2
    c
    • 2
    • 2
  • e

    Eugen Martynov

    05/02/2025, 11:13 AM
    Kotlin 2.2.0 - Can not find kotlin dsl for gradle to work with compiler warnings. I see only command line, means I need to use free compiler args? https://kotlinlang.org/docs/whatsnew-eap.html#use-cases
    šŸ‘Œ 1
  • k

    kevin.cianfarini

    05/04/2025, 3:11 AM
    Would it be possible for the Kotlin compiler to allow interface implementation by extension? For example, something like:
    Copy code
    // An interface in code I define. 
    interface Thing { ... }
    
    // A type from a third party library. 
    class SomeThirdPartyType
    
    // An implementation of Thing based on the public API of SomeThirdPartyType that I own. 
    extension SomeThirdPartyType : Thing { ... }
    A really naive implementation of this could generate some wrapper like
    SomeThirdPartyType$ThingImplWrapper
    that, whenever an instance of
    SomeThirdPartyType
    is referenced as a Thing, it is boxed by the generated wrapper. Are there unsuspecting ways which something like this might actually be terrible?
    y
    • 2
    • 6
  • p

    PHondogo

    05/05/2025, 8:54 AM
    Starting from 2.2.0-Beta2 got warning when using assignment to dispatherReceiver. I see there was rework of parameters API. Where can i find migration docs to new parameters API? Found this link (https://youtrack.jetbrains.com/articles/KT-A-601/New-IR-parameter-API-migration-guide) but it leads to 'Article not found'
    d
    • 2
    • 1
  • w

    Waldemar Kornewald

    05/05/2025, 2:17 PM
    Hello, what would be the advantages/disadvantages of the analysis API vs. a FIR compiler plugin for some static code checks? Wouldn't a FIR checker plugin minimize the CI run times because it runs directly with the compilation while AA requires an additional parse/analysis step? Also, as-you-type checks would only be possible with a FIR plugin, right (unless everyone on the team installs an IDE plugin)? AA has a more stable API, but let's pretend that doesn't matter so much in this case. Does AA just provide a more high-level / convenient API than FIR or would the checks have similar complexity in both? As a more extreme example, wouldn't a detekt-like FIR (maybe +IR) compiler plugin provide a better user experience since all checks would be visible on-the-fly in the IDE? Or would such a plugin cause too much overhead because it has maybe 200 checks that run all the time while typing?
    d
    • 2
    • 4
  • d

    Drew Hamilton

    05/06/2025, 2:57 PM
    If I call
    processAllDeclaredCallables
    inside of
    generateFunctions
    I get a recursive loop that ends in a StackOverflowError. Is it intended that I should opt-in to
    DirectDeclarationsAccess
    in this case?
    d
    • 2
    • 4
  • z

    Zac Sweers

    05/06/2025, 5:05 PM
    what's the best way for a compiler plugin to report verbose logging that's not a compiler warning? It seems that anything less than error/warning will be swallowed by the MessageCollector. I suspect they're getting routed through gradle's logging levels, but considering enabling --debug logging in gradle yields literal gigabytes of noisy logs it's less than ideal. it seems that printlns are also swallowed
    šŸ‘€ 2
    šŸ‘ 1
    o
    • 2
    • 1
  • j

    Jake Woods

    05/08/2025, 10:55 PM
    Using FIR is it possible to generate a function stub that is local to another annotated function? I.e. say I have:
    Copy code
    @MyPlugin fun foo() {}
    Is it possible to generate:
    Copy code
    @MyPlugin fun foo() {
      local fun callMyPlugin() {}
    }
    🚫 1
  • y

    Youssef Shoaib [MOD]

    05/09/2025, 2:42 PM
    Is there something like
    ClassGeneratorExtension
    but for JS or Native? As in, I want to modify the final generated code.
    🚫 1
  • a

    Alexander Ioffe

    05/09/2025, 2:58 PM
    I've noticed in that the backend IR has various inserted methods where casting is needed e.g. if you do
    (x:Int) >= (x:Double)
    it will insert a
    toDouble
    making it
    (x:Int).toDouble() >= (x:Double)
    . On the
    toDouble
    IrCall instance, is there some way of knowing whether this is something that the user actually coded or if it was inserted by the compiler?
  • y

    Youssef Shoaib [MOD]

    05/10/2025, 12:10 PM
    The testing setup in https://github.com/demiurg906/kotlin-compiler-plugin-template seems to be out of date with 2.2.0. Is there an updated version somewhere?
    d
    • 2
    • 6
  • m

    Marius Barbulescu

    05/10/2025, 2:15 PM
    What is the recommended way to migrate
    FirSessionFactoryHelper.INSTANCE.createSessionWithDependencies
    when moving to Kotlin +2.1? The usage is in Openrewrite https://github.com/openrewrite/rewrite/blob/main/rewrite-kotlin/src/main/java/org/openrewrite/kotlin/KotlinParser.java#L475
    d
    • 2
    • 1
  • v

    vladimirsitnikov

    05/10/2025, 2:45 PM
    Is there a reason kotlinc generates sam wrappers within inline functions? In other words, the bytecode for the following function becomes significantly worse when the function is inline:
    Copy code
    inline fun test(x: java.util.stream.Stream<out String>) {
        x.map {
            it.length  
        }
    }
    • 1
    • 4