https://kotlinlang.org logo
Join Slack
Powered by
# k2-adopters
  • t

    toadzky

    11/17/2024, 5:38 AM
    hey, i'm playing around with a k2 compiler plugin to auto-magically integrate annotated suspend functions with a framework that doesn't understand them and doesn't know how to wrap them. i've got through the "find the functions i want to re-write" part and the "replace it with a dummy version" part. right now i'm trying to generate a function that ends up being something like
    Copy code
    @Annotation
    fun myFunction(...) {
      CoroutineScope(Dispatchers.Default).async {
        // insert original function statements here
      }
    }
    but the plugin context can't find either the
    CoroutineScope(CoroutineContext)
    factory function or the
    async
    extension function (though it's not particularly clear how to find extension functions since there's no docs). when i try to have the symbol provider look up top level functions for the coroutines package, it finds others, but not those (and not
    launch
    either). what's the correct way to go about finding those function symbols so i can have my plugin invoke them? this is what i'm currently doing:
    Copy code
    pluginContext.referenceFunctions(CallableId(
      packageName = StandardNames.COROUTINES_PACKAGE_FQ_NAME,
      callableName = Name.identifier("CoroutineScope")
    ))
    e
    d
    • 3
    • 17
  • a

    axeon

    11/19/2024, 12:19 PM
    Hello, is this the right place to ask about the K2 Analysis API? I previously posted this question in #C7L3JB43G, but now I'm not sure if it was the appropriate channel.
  • a

    Abhimanyu

    11/23/2024, 12:46 PM
    Hi 👋 , Cross-posting here since the error message and the issue tracker references K2. Any assistance would be greatly appreciated! thank you color https://kotlinlang.slack.com/archives/C0B8H786P/p1732346951357729
    thank you color 1
    m
    t
    • 3
    • 22
  • h

    hho

    11/27/2024, 2:26 PM
    It's happening! https://github.com/JetBrains/kotlin/releases/tag/v2.1.0
    K 6
    🎉 5
  • e

    Eugen Martynov

    11/29/2024, 7:35 AM
    Ran profiler with our scenarios with 2.1 and I see significant drop (sometimes 20%). What is your experience?
    r
    t
    • 3
    • 17
  • a

    Anirudh

    12/11/2024, 1:05 PM
    not an early adopter but have this feedback: I noticed that the K2 mode also doesn't show certain suggestions, like making non-publicly accessed methods private (the K1 mode shows this suggestion).
    m
    d
    • 3
    • 3
  • x

    Xad Kile

    12/11/2024, 2:14 PM
    Hi all, I am trying to modify
    myLambda
    passed to a function call like this one
    Copy code
    fun outerFunction(){
       someFunctionCall(myLambda = {...}, otherStuff)
    }
    Ideally, I would like to generate an entirely new lambda, and replace the current
    myLambda
    . I have managed to do all that except for finding a declaration parent for my new lambda. I am doing this within
    visitCall
    and I think the correct parent should be whatever is calling
    someFunctionCall
    , in this case that is
    outerFunction
    . However, I cannot find a way to get the declaration of
    outerFunction
    from the
    IrCall
    at
    visitCall
    . Is this the proper way to find parent for my new lambda? Am I missing something here? Thank you
  • e

    Eugen Martynov

    12/18/2024, 12:46 PM
    Can not find how can I turn off the deprecation warnings with 2.1 - hovering with mouse doesn't who me the value for the compiler. (I'm in Android Studio).
    d
    • 2
    • 8
  • o

    Ola Adolfsson

    12/27/2024, 9:11 AM
    Hej 🙂 Whats the difference between
    jsNodeDevelopmentLibraryDistribution
    and
    jsNodeProductionLibraryDistribution
    ? I mean just that you should use production for production 🙂. I can't find any information. Is anyone faster, etc?
    c
    • 2
    • 3
  • g

    gpopides

    01/02/2025, 9:48 PM
    Hello, can we specify in
    extraWarnings
    option that shipped with 2.1 a package to be ignored? Currently protobuf compilation adds modifiers in the compiled classes and we get the redundant modifier warning Ideally we would like to ignore the package/directory that we output the classes to
    d
    • 2
    • 1
  • r

    ritesh

    01/06/2025, 7:59 AM
    👋 Hello, I enabled
    enableStrongSkippingMode
    in my project for compose. It fails for a specific piece of code when running Junit tests for compose, the failure seems to be streaming from compose-compiler/plugin during the IR lowering phase. More in 🧵
    d
    s
    • 3
    • 11
  • p

    Priyabrata Naskar

    01/09/2025, 7:58 AM
    In kotlin 2.1.0 and above synchronisation for int is prohibited. While ANDROID STUDIO(version: Meerkat 2023.3.1 Nightly) is not showing any error, though getting error during compilation. And there's no issue in kotlin 2.0.0. Wanted to understand if this is a bug or intended change in kotlin 2.1.0?
    k
    • 2
    • 3
  • m

    Melih Aksoy

    01/17/2025, 8:08 PM
    I have a strange error when I work with K2 - I can't work with returned types of functions unless I declare the return type, otherwise property type is
    ERROR
    and autocompelete etc. does not work - I tried to load with different versions of AS as well as invalidate / restart / nuking .idea etc. but nothing except disabling k2 fixed it so far any ideas ?
    a
    • 2
    • 6
  • o

    Olaf Gottschalk

    02/10/2025, 8:41 AM
    I just realized, much to my surprise, that in some projects where I still deliberately use Kotlin 1.9.25, the Kotlin standard library was bumped to 2.0.21 due to some transitive dependencies of libraries I updated. I did not realize this before and it's already like this in production... without problems. Is there an inherent risk in using the Kotlin 1.9.25 compiler / toolchain and the Kotlin standard lib already on 2.0.21? Why did I notice just now? I wanted to update one of my libs again to their latest version and because those now went to Kotlin 2.1.+, this breaks because there is a binary incompatibility introduced between Kotlin 2.0 and Kotlin 2.1... :(
    m
    s
    +3
    • 6
    • 13
  • f

    François

    02/24/2025, 10:08 AM
    Hi, I made an issue about K2 and code completion, until it was process, someone already met this issue?
    m
    s
    • 3
    • 3
  • f

    florent

    04/25/2025, 1:10 PM
    Hi, I switched Android studio to use k2 and it replaces my imports by imports * when I ask to autocomplete a
    when
    . Is it something known? And of course, I have disabled * imports on the kotlin code style. Thanks for your time!
    a
    r
    • 3
    • 6
  • m

    martmists

    04/29/2025, 6:07 PM
    How do I make IntelliJ update errors/warnings when I update code? As it is, I need to reopen after every change to see the error removed.
    r
    a
    • 3
    • 10
  • n

    nerses

    05/06/2025, 11:41 PM
    is this a compiler bug?
    Copy code
    open class Parent(
        open val numbers: List<Int>
    ) {
        val sortedNumbers: List<Int> = numbers.sorted()
    }
    
    class Child(
        override val numbers: List<Int>
    ): Parent(numbers)
    
    fun main() {
        println(Child(emptyList()).sortedNumbers)
    }
    it fails with
    Copy code
    Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.collections.CollectionsKt___CollectionsKt.sorted, parameter <this>
    	at kotlin.collections.CollectionsKt___CollectionsKt.sorted(_Collections.kt)
    	at Parent.<init>(Blah.kt:4)
    	at Child.<init>(Blah.kt:9)
    	at BlahKt.main(Blah.kt:12)
    	at BlahKt.main(Blah.kt)
    e
    • 2
    • 6
  • a

    aidanvii

    05/07/2025, 8:10 AM
    can someone explain to me why this is a compiler error in pre Kotlin 2.0 versions but a warning in 2.0+? https://pl.kotl.in/IinrYXjPh 2.0+ just gives a
    INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION
    warning It’s worth mentioning if you specify the types explicitly, it will result in a compiler error in 2.0+, but not with inferred types 🤷
    d
    • 2
    • 1
  • k

    kevin.cianfarini

    05/13/2025, 1:33 PM
    Hi folks. I think I’ve uncovered a minor bug with the Kotlin K2 compiler. I’ve enabled
    -Werror
    on my project and it instructed me to delete an
    else
    branch that was previously required for a
    when
    statement with an
    expect enum class
    as the subject. I flagged in in the #C0B8H786P channel here, and after discussing, I think there’s two issues: 1. This code shouldn’t compile at all since expect enums can have less entries than their actual counterparts. 2. The else branch shouldn’t have been flagged as unnecessary by the compiler. Does this seem like it’s an actual bug? Here’s the PR where I surfaced this inconsistency. cc @Anna Kozlova
    d
    • 2
    • 6
  • c

    Cies

    05/14/2025, 8:10 AM
    I'm sad to announce that we consider switching back to 1.9.x since we get smartcast issues after switching a branch, where rebuilding is the only way to fix it. It's a major drain on productivity.
    • 1
    • 1
  • c

    CLOVIS

    05/15/2025, 12:38 PM
    Are there any news on the implementation of Type-Matching completion? It's starting to be very frustrating not to have access to it. We have many enums that have the same name. At the moment the only reliable way to use an enum is to CTRL Click the parameter name, invoke "copy reference" to get the FQDN, go back and paste that. Any other way, IntelliJ imports the wrong enum.
    a
    • 2
    • 14
  • a

    Andreas Martin Mørch

    05/20/2025, 7:53 AM
    I'm getting this after upgrading our project to Kotlin 2.1.21 and building:
    Copy code
    java.lang.IllegalArgumentException: Only componentN functions should be cached this way, but got: hashCode
    	at org.jetbrains.kotlin.fir.backend.Fir2IrDeclarationStorage.cacheIrFunctionSymbol(Fir2IrDeclarationStorage.kt:426)
    	at org.jetbrains.kotlin.fir.backend.Fir2IrDeclarationStorage.getIrFunctionSymbol(Fir2IrDeclarationStorage.kt:1133)
    	at org.jetbrains.kotlin.fir.backend.Fir2IrDeclarationStorage.getIrFunctionSymbol$default(Fir2IrDeclarationStorage.kt:1101)
    	at org.jetbrains.kotlin.fir.backend.generators.Fir2IrDataClassGeneratedMemberBodyGenerator$MyDataClassMethodsGenerator$irDataClassMembersGenerator$1.getHashCodeFunctionInfo(Fir2IrDataClassMembersGenerator.kt:362)
    	at org.jetbrains.kotlin.ir.util.DataClassMembersGenerator.getHashCodeOf(DataClassMembersGenerator.kt:282)
    	at org.jetbrains.kotlin.ir.util.DataClassMembersGenerator$MemberFunctionBuilder.getHashCodeOfProperty(DataClassMembersGenerator.kt:229)
    	at org.jetbrains.kotlin.ir.util.DataClassMembersGenerator$MemberFunctionBuilder.generateHashCodeMethodBody(DataClassMembersGenerator.kt:211)
    	at org.jetbrains.kotlin.ir.util.IrBasedDataClassMembersGenerator.generateHashCodeMethod(DataClassMembersGenerator.kt:367)
    I only found this issue where someone had a similar issue, but they get it by using the IJ debugger and evaluating an expression: KT-70376 K2 IDE / Kotlin Debugger: IAE “Only componentN functions should be cached this way, but got: toString” on evaluating toString() method for value class I tried a variety of versions from 2.0.x to 2.2.0-RC giving me the same error. Is there any way to figure out which code this exception refers to? Maybe that will make it possible to create a minimal reproducer
    a
    d
    • 3
    • 40
  • g

    Giorgio Vespucci

    05/29/2025, 1:12 PM
    I'm experiencing some unreal
    "Unreachable Code"
    with K2 Mode active. Has anyone got the same issue?
    d
    r
    • 3
    • 11
  • e

    Eugen Martynov

    06/30/2025, 4:22 PM
    Let me confirm (profile again), but it looks like clean builds with 2.2.0 are slower comparing to 2.1.x by around 20%.
    m
    t
    • 3
    • 5
  • m

    Marharyta Nedzelska

    07/01/2025, 8:09 AM
    Hey there, We’re using Analysis API for our static code analyzer. Since the release 2.2, we can’t find the corresponding version of the Analysis API to upgrade. Since today we also see 401 error on the previous artifact: Could not GET 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies/org/jetbrains/kotlin/analysis-api-standalone-for-ide/2.1.21/analysis-api-standalone-for-ide-2.1.21.pom'. Received status code 401 from server: Unauthorized
    t
    m
    • 3
    • 3
  • m

    Marharyta Nedzelska

    07/02/2025, 2:01 PM
    Hey there, it’s again me from Sonar. We just upgraded to 2.2 and some of our tests started failing. After looking deeper we realized that the comments in the middle of String concatenations are not visited due to this change: https://github.com/JetBrains/kotlin/commit/f33566e0d7883ca3c56d2552cc4da0cbf6ad966a I understand the reasoning behind this, however I believe that PSI was supposed to be used as full fidelity tree, implying that the default should be true. However, just setting it to true will keep the nested KtBinaryExpressions of string concatenations in the llist, not their children. And this can lead to the stack overflow. I’m not sure if there’s a bug there or it’s how it is supposed to be? So decided to ask here before raising anything in the Youtrack.
    very nice 1
    ✅ 1
    i
    • 2
    • 1
  • x

    X Jia

    07/17/2025, 9:45 AM
    I'm trying to migrate from the deprecated putValueArgument in IrMemberAccessExpression and need some guidance. There is this brief doc in the source file: "Sets one of arguments that correspond to IrParameterKind.Context or IrParameterKind.Regular parameters. This is, index corresponds to IrFunction.valueParameters list, and not IrFunction.parameters, which also includes receiver parameters. This is a deprecated API! Use arguments instead. E.g. for code call.putValueArgument(parameter.indexInOldValueParameters, ...) the replacement should be call.arguments[parameter.indexInParameters] = ... If you need to know the IrParameterKind of the arguments, reach out to the corresponding function's parameter. Details on the API migration: KT-68003" Say I want to migrate:
    Copy code
    putValueArgument(0, expr)
    I'm not clear on how to get "parameter.indexInParameters" in this case. And where can I find "the API migration: KT-68003"? Any help please.
    d
    w
    • 3
    • 2
  • a

    agrosner

    07/24/2025, 7:04 PM
    has anyone noticed that the IDE does not always highlight invalid functions or show analysis until project builds in a large project? ive noticed that for a bit, in K2 Mode. as if the analyzer stops running or crashes 🤷
  • s

    segunfamisa

    07/31/2025, 4:41 PM
    hey folks, i'm working on migrating some PSI code from K1 to K2. The usecase is this:
    Copy code
    fun foo() {
      GlobalScope.launch {
        // anonymous suspend function <===
        try {
          delay(1_000)
        } catch (_: Exception) {
          // general error handling
        }
      }
    }
    I need to be able to tell if the try-block is running within a suspend function (as is this case). I have this so far:
    Copy code
    // visitTryExpression
    val function = expression.getParentOfType<KtFunction>(strict = true) ?: return
    analyze(function) {
      val symbol: KaAnonymousFunctionSymbol = function.symbol
      // symbol.isSuspend does not exist
    }
    I noticed that
    KaAnonymousFunctionSymbol.isSuspend
    does not exist, even though
    KaNamedFunctionSymbol.isSuspend
    exists. My question is: how does one get whether an anonymous function/lambda is a suspend function in the analysis API?e
    r
    • 2
    • 4