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

    Caleb B

    11/10/2025, 3:38 PM
    Is there any way to get the type information for the RHS of an assignment when using an FIR AssignmentAltererExtension? Or do you just need to blindly change the call target and defer checking if it's a valid target to a later FIR stage?
  • m

    martmists

    11/10/2025, 4:40 PM
    Copy code
    Caused by: java.lang.AssertionError: Unexpected IR element found during code generation. Either code generation for it is not implemented, or it should have been lowered:
    FUN name:<anonymous> visibility:public modality:FINAL <> (it:kotlin.Any) returnType:kotlin.Any
    How do I fix this? I'm trying to build a lambda, and in the parent declaration (see thread) the generated IR largely seems fine to me.
    y
    • 2
    • 12
  • y

    y9san9

    11/11/2025, 8:26 AM
    Hey guys. Am I stupid or it is a bug in the compiler? I tried 3 versions (2.2.20, 2.2.21, 2.3.0-Beta2) and it has this warning. I think it's changing though.
    d
    • 2
    • 7
  • c

    Caleb B

    11/11/2025, 10:55 PM
    Can you set the priority of your compiler plugin? I want to make sure my plugin is run last so I don't conflict with others treading the same ground.
    j
    z
    +3
    • 6
    • 15
  • z

    Zac Sweers

    11/12/2025, 6:38 PM
    I'm looking into an odd IC issue someone reported with Metro, where we do recompile and can look up a given recompiled class, but the class is missing all its declarations and annotations. Usually with IC it's a matter of linking two files/symbols together in compilation, but I've not encountered a situation where we get a symbol and it's just lossy. In this case, the symbol it's trying to read is in a separate upstream compilation ref: https://github.com/ZacSweers/metro/pull/1349
    d
    • 2
    • 34
  • c

    Caleb B

    11/12/2025, 10:06 PM
    Since there's no concrete plugin-priority system, I wanted to see if anyone could help me figure out how to design my "overloaded setters" plugin such that it doesn't need to run last. Details in thread.
    • 1
    • 4
  • c

    crowforkotlin

    11/14/2025, 2:01 AM
    # Kotlin Compiler IR & FIR pdf https://ssw.jku.at/Teaching/BachelorTheses/2025/Weinstabl_David.pdf
    👏 4
    🏆 4
    👀 2
    y
    j
    +2
    • 5
    • 6
  • j

    Jonas

    11/14/2025, 8:38 AM
    The IntelliJ feature where compiler generated code is shown inline is quite new, right? @Zac Sweers showed it in his stream with Code with Italians. I currently try to figure out in which IntelliJ Version it was added and when it will probably land in Android Studio.
    solved 1
    h
    z
    • 3
    • 8
  • j

    Javier

    11/14/2025, 3:07 PM
    Is it not possible to find annotated references from dependencies with FIR without knowing the exact
    FqName
    , right? So the only workaround about this is that the Gradle Plugin uses something like Classgraph to find those references and pass them to the compiler when syncing/building?
    👌 1
    l
    • 2
    • 6
  • m

    martmists

    11/15/2025, 10:44 PM
    Running into a weird issue where a IrFunctionReferenceImpl passed as argument to an irCall, it seems to get lowered to
    null.INSTANCE
    , what could be the cause of this? Sample snippet where I pass a ctor reference:
    Copy code
    val result = irCall(apply).apply {
        typeArguments[0] = klass.defaultType
        dispatchReceiver = product
        arguments.addAll(1,
            listOf(
                builder,
                IrFunctionReferenceImpl(
                    klass.startOffset,
                    klass.endOffset,
                    pluginContext.irBuiltIns.functionN(ctor.nonDispatchParameters.size).typeWith(*ctor.nonDispatchParameters.map { it.type }.toTypedArray(), klass.defaultType),
                    ctor.symbol,
                    0,
                )
            )
        )
    }
  • f

    Fergus Hewson

    11/16/2025, 10:01 PM
    Copy code
    WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
    WARNING: sun.misc.Unsafe::objectFieldOffset has been called by com.intellij.util.containers.Unsafe (file:/Users/fergushewson/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler/2.2.20/cdea4080fdae6867e9826af835df82e7f2b48a16/kotlin-compiler-2.2.20.jar)
    WARNING: Please consider reporting this to the maintainers of class com.intellij.util.containers.Unsafe
    WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
    I'm getting this message when writing a compiler plugin, where/how should I report this?
    e
    • 2
    • 3
  • c

    Caleb B

    11/17/2025, 12:22 AM
    How robust is the "run .kts in the context of a project" system? Is it secure enough to be used as a
    constexpr
    interpreter?
    • 1
    • 1
  • m

    martmists

    11/18/2025, 12:45 AM
    Running into a weird issue where if I use kotlin SAM types my code compiles but crashes at runtime because the lambda can't be cast to the java SAM type, but using java SAM types in my IR generation causes
    Copy code
    Unexpected IR element found during code generation. Either code generation for it is not implemented, or it should have been lowered:
    FUNCTION_REFERENCE 'private final fun _init_$0 (receiver: com.martmists.serialization.TestData): <http://kotlin.Int|kotlin.Int> declared in com.martmists.serialization.TestData.Companion' type=@[FlexibleNullability] java.util.function.Function<@[FlexibleNullability] O of com.mojang.serialization.MapCodec.forGetter?, @[FlexibleNullability] A of com.mojang.serialization.MapCodec?>? origin=LAMBDA reflectionTarget=null
    What am I doing wrong? Pastebin link: https://pastebin.com/FCSX76GE (uses kotlin types, and crashes when the lambda is cast to Function)
    l
    • 2
    • 2
  • j

    Javier

    11/18/2025, 3:20 PM
    I have cloned the Kotlin Compiler Plugin template and after adding a new test I am getting the error next error:
    Copy code
    Module Module <CommonOne> doesn't contain package <http://com.foo.dev.app|com.foo.dev.app>
    It is throwed inside this function:
    Copy code
    override fun getPackage(fqName: FqName): PackageViewDescriptor {
        val symbolProvider = session.symbolProvider
        if (symbolProvider.hasPackage(fqName)) {
            return FirPackageViewDescriptor(fqName, this)
        }
        error("Module $moduleData doesn't contain package $fqName")
    }
    The test file is
    Copy code
    // MODULE: CommonOne
    // file: CommonOneFooDao.kt
    
    package com.foo.common.one
    
    import androidx.room.Dao
    
    @Dao
    interface CommonOneFooDao {
    
        fun foo()
    }
    
    // MODULE: FeatureOne(CommonOne)
    // file: FeatureOneFooDao.kt
    
    package com.foo.feature.one
    
    import androidx.room.Dao
    
    @Dao
    interface FeatureOneFooDao {
    
        fun foo()
    }
    
    
    // MODULE: DevApp(FeatureOne, CommonOne)
    // file: main.kt
    package com.foo.dev.app.feature.one
    
    fun main() {
    
    }
    b
    • 2
    • 10
  • c

    Caleb B

    11/18/2025, 8:16 PM
    Can compiler plugins stop a vanilla Kotlin compiler error/diagnostic from appearing? I'm working on a composite-annotations plugin (like Spring), and to do it I need to be able to apply any annotation to an annotation class, not just ones with
    ANNOTATION_CLASS
    as an allowed target.
    j
    b
    • 3
    • 5
  • m

    martmists

    11/18/2025, 11:36 PM
    How can I see annotations through type aliases? e.g. I have
    typealias CMyType = @CustomAnnotation(...) MyType
    but inspecting the IrType shows no annotation and printing the fq name just shows MyType. using the expanded form instead of the type alias works fine. I checked in parent declarations and dumping them always shows the original type without annotations.
    🤔 1
  • f

    Fergus Hewson

    11/19/2025, 7:36 AM
    I have a
    FirDeclarationGenerationExtension
    that I am using to generate a nested class with the same params as a data class plus custom setters, flows for each property and and all flow. Is the correct process to generate callables for each method/property in
    getCallableNamesForClass
    and the generate properties and functions in
    generateProperties
    and
    generateFunctions?
    To do this I have to parse the constructor for the supertype twice or cache callable information in the extensions and to generate the method signatures I need? Am I missing something about how this extension should work? If anyone has similar work. I could read I would really appreciate it too!
    b
    • 2
    • 2
  • j

    Javier

    11/19/2025, 12:23 PM
    I am using
    buildArrayliteral {}
    to populate an array of an annotation I am trying to build this:
    Copy code
    @Database(
        entities = [
            OneEntity::class,
            TwoEntity:class,
        ]
    )
    abstract class FooDatabase : RoomDatabase()
    Everything is created, but building the arrow with the function above fails due `Expected expression
    FirArrayLiteralImpl
    to be resolved`. But I do not find a way to resolve this expression.
    d
    • 2
    • 9
  • c

    Caleb B

    11/19/2025, 5:17 PM
    Given a reference to a property (either as an
    FirPropertySymbol
    or
    FirNamedReference
    ), how do you get the class that "owns" said property? (The receiver if it's an extension, or the actual owning class if it's a standard property.) I have
    R|<local>/inst|.R|/MyClass.bar|
    , I just can't figure out how to go one level up to
    R|<local>/inst|.R|/MyClass|
    .
    ✅ 1
    d
    y
    • 3
    • 3
  • c

    Caleb B

    11/19/2025, 7:41 PM
    When constructing new FIR, how would you emit
    this@R|/MyClass|.R|/MyClass.bar| = R|<local>/value|
    ? I'm assuming it's through
    buildVariableAssignment
    , but I can't figure out what builders to wire into the LValue and RValue.
    j
    • 2
    • 10
  • o

    Oliver.O

    11/20/2025, 11:34 AM
    It looks like IC is working differently, depending on the KGP variant: KT-82560 shows a case where it works with
    kotlin("multiplatform")
    , but not
    kotlin("jvm")
    . Is this a known situation and will it change?
    t
    d
    • 3
    • 24
  • t

    tapchicoma

    11/20/2025, 3:23 PM
    Hey compiler plugin developers. I am curious to gauge the following idea with the following rough outline - We are thinking about introducing compiler plugin devkit in a form of separate Gradle plugin. The core idea is that it will create a set of the following source sets: • API - common api for the compiler plugin (for example compiler plugin options) • implementations for concrete Kotlin compiler version. The supported versions are defined in the DSL and will be provided as
    compileOnly
    dependencies by devkit plugin • optional bootstrap for Gradle and Maven plugins The project will publish a set of publications for API + implementation for every supported Kotlin compiler version with additional (Gradle or some way) attribute. Based on this attribute Kotlin build plugins could select proper publication for used in the project Kotlin compiler version. What do you think about it?
    🔝 3
    o
    y
    +6
    • 9
    • 43
  • j

    Javier

    11/20/2025, 4:18 PM
    I am applying the plugin via Gradle and referencing the generated class in the code is working correctly via terminal, but in the IDE it is not found, so red. I have marked as false the registry property
    kotlin.k2.only.bundled.compiler.plugins.enabled
    . Am I missing something?
    h
    • 2
    • 6
  • m

    mikehearn

    11/20/2025, 4:56 PM
    Quick optimization question - is kotlinc capable of moving the initialization of Regex objects into static fields automatically? GPT-5 loves to inline Regex("..") into the place where it's used, which could be quite inefficient and I'm not sure HotSpot will fix that
  • c

    Caleb B

    11/20/2025, 5:36 PM
    In FIR, how do you get all callables for a given class, including extension methods and inherited members?
    FirClassSymbol<*>#declaredX
    only gives class members. This is specifically for diagnostics, so it should be resolved at that point, right?
    y
    d
    • 3
    • 3
  • p

    Pablichjenkov

    11/20/2025, 10:41 PM
    https://kotlinlang.slack.com/archives/C2R77UD35/p1763678424304139
    solved 1
    ✅ 1
    • 1
    • 1
  • m

    martmists

    11/23/2025, 1:00 PM
    Copy code
    @Target(AnnotationTarget.TYPE)
    @Retention(AnnotationRetention.SOURCE)
    annotation class CodecLocation(val klass: KClass<*>, val field: String)  // Ideally I could do CodecLocation(val prop: KProperty<*>) to specify as @CodecLocation(Codecs::B_CODEC) but that doesn't seem to work
    
    @Codec
    data class A(
        val b: @CodecLocation(Codecs::class, "B_CODEC") B
    )
    
    typealias CodecB = @CodecLocation(Codecs::class, "B_CODEC") B
    
    @Codec
    data class A2(
        val b: CodecB
    )
    In A I can grab
    param.type.annotations[0]
    to get the CodecLocation annotation, but in A2 it seems to just resolve as
    B
    with no annotations present. How can I still get the annotation in A2?
  • f

    Fergus Hewson

    11/24/2025, 3:38 AM
    During IR phase, when is best time to create backing fields for properties? I have StateFlows which are properties and I want to generate backing MutableStateFlows in the constructor using args from that constructor for the initial values. Then I need to wire the properties up to their associated backing fields, I am getting concurrent modification exceptions for adding fields during the visit class call. Is there a correct way of wiring this up?
  • d

    Devanshu Pathsariya

    11/24/2025, 7:48 AM
    Hi, I am creating compile-time di framework for kmp, Now i want to produce a class after the compilation of a shared module(is concretely used in a native module) which can access the classes,function defined even in the transitive module just like hilt does for jvm?
  • f

    Fergus Hewson

    11/24/2025, 5:53 PM
    How do you make generated FIR visible in the IDE? I can see the seralizer() method from classes annotated with @Serializable, but not my generated nested classes. Is kotlinx.serialization public? Or is there an example repo I can look at to figure out how this works?
    m
    • 2
    • 3