https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compiler
  • h

    hfhbd

    08/26/2021, 8:18 AM
    Hey, I am getting some straight errors during JS IR compiling, but how do you get the causing file?
    java.lang.IllegalStateException: IrSimpleFunctionSymbolImpl is already bound: FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:<Uninitialized>
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindableSymbolBase.bind(IrPrivateSymbolBase.kt:64)
    d
    • 2
    • 7
  • d

    Dave

    08/26/2021, 9:48 AM
    Hi, I use
    IrGenerationExtension
    to modify the IR for the current module. But is there a way to modify the IR coming from other modules? I know that seems odd. But the use case is in the context of JS. When a 'binary' is created, kotlin-IR-JS generates a js file that contains all the depended on modules also, and I want to adjust the JS that is generated for a depended on module - i.e. via the IR. thanks
    b
    • 2
    • 2
  • j

    jw

    08/27/2021, 1:09 AM
    for annotations you can use https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-optional-expectation/
    a
    • 2
    • 1
  • v

    Vojtech Hrdina

    08/27/2021, 4:10 PM
    Hi, is there any way how to debug compile issues? I am trying to run
    ./gradlew :app:compileDebugUnitTestKotlin --debug
    and it always stuck with following message
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
    2021-08-27T16:31:11.764+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
    I already identified test file which causing this issue but I don’t know what could be wrong and it is stuck forever. AGP 4.2.0 Kotlin 1.5.0 Gradle wrapper 6.8.3 Java 11 macOS 11.5.2, Ubuntu 16.04
    org.gradle.jvmargs=-Xmx4608M -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    org.gradle.parallel=true
    org.gradle.caching=true
    android.enableD8=true
    android.useAndroidX=true
    android.enableJetifier=true
    kapt.use.worker.api=true
    kapt.incremental.apt=true
    kapt.include.compile.classpath=false
    android.databinding.incremental=true
    android.forceJacocoOutOfProcess=true
    d
    • 2
    • 2
  • r

    raulraja

    08/31/2021, 10:15 AM
    Hi!, I’m looking for publicly available snapshots and dev releases of the Kotlin compiler to depend on for some testing. Does the Kotlin compiler get published as snapshot, dev or nightly in some repo beside what’s available in maven central? Thanks!
    d
    • 2
    • 2
  • u

    ursus

    09/06/2021, 1:50 AM
    Hi, I'm trying to build a compiler plugin, and am working my way throught the AST, I have a
    KtNamedFunction
    . Is there a way to check if the type it represents, is a subclass of some another type? Or is that simply too soon to say at that point?
    y
    r
    • 3
    • 17
  • t

    Tomasz Krakowiak

    09/06/2021, 6:09 AM
    Hello, I want to implement compiler plugin, that creates something like macro from annotated function. Something that would take something like:
    fun styled(block : RuleSet, @CallerPackage packageName)
    and introduce synthetic macro-like function:
    fun styled(block : RuleSet) = styled(block, callerPackage())
    and wherever
    styled(block)
    is used, plugin would replace calls with
    styled(block, "actual.callers.package.name")
    . Are there any good examples I could use? Maybe somewhere in compose?
    s
    r
    • 3
    • 2
  • u

    ursus

    09/07/2021, 12:22 PM
    Stupid question, I can attach a debuger into a compiler plugin, but how do I print something to console?
    println
    doesn't seem to work, and I have
    verbose
    flag in compile options as well (building via gradle)
    r
    s
    y
    • 4
    • 3
  • m

    mcpiroman

    09/11/2021, 10:25 AM
    How can I deep copy a IR tree? It has to be a really deep copy, no references between trees shall be left. I've tried this:
    val symRemapper = DeepCopySymbolRemapper()
    val moduleCopy = DeepCopyIrTreeWithSymbols(symRemapper, DeepCopyTypeRemapper(symRemapper)).visitModuleFragment(module)
    But it gives me
    java.lang.IllegalArgumentException: Non-remapped symbol FILE fqName:kotlin.ranges
    y
    s
    • 3
    • 4
  • g

    Gamadril

    09/15/2021, 8:11 PM
    Hi. I created a kotlin compiler plugin which adds kotlinx.serialization.Serializable annotation to specific classes automatically. However even if I see in the built decompiled class file the added annotation, the whole serializer code for that class of the kotlinx-serialization plugin is not generated. So is my plugin executed after the kotlinx-serialization plugin? How can this be fixed? I've implemented it as ClassBuilderInterceptorExtension with DelegatingClassBuilder if it's important
    👀 3
    b
    l
    y
    • 4
    • 6
  • e

    eygraber

    09/17/2021, 2:06 AM
    Not sure if this is the right channel for this, but is there any way to force using parameter names when calling a function?
    e
    a
    • 3
    • 3
  • a

    Anastasia Birillo [JB]

    09/17/2021, 2:32 PM
    Hello everyone! We developed a plugin for the Kotlin compiler that leverages the flows of the standard reflection approach and can find classes, objects or functions by some conditions in compile-time. The current latest version is ready and stable! Two ways of using the plugin are supported: by limited DSL (searching of classes and objects by supertypes and annotations; and searching of functions by signature and annotations) and by extended DSL (searching of classes and objects by custom condition and supertype; and searching of functions by custom condition and signature). Since we use IR generation, the plugin can be used by all platforms (JVM, Nativa and JavaScript). Although currently, we can analyze only kt files. Additionally, the plugin uses a code generation approach in limited DSL to support compile-time reflection in libraries. It means, if you have a library that uses Reflekt and you call something from this library in your project, all Reflekt calls will be in the compile-time. Currently we support 1.5.30, 1.5.21, 1.5.20, 1.5.10, 1.5.0 Kotlin versions. Unfortunately, we do not support incremental compilation yet, but in the next release, we will be! We will be happy if the plugin would be helpful for you! If you are interested in this project and have some ideas for improving the plugin, please don’t hesitate to contact me!
    ❤️ 4
    🚀 14
    z
    m
    +3
    • 6
    • 13
  • c

    Callum Seabrook

    09/22/2021, 4:23 PM
    Not sure where to ask this, but I think this is the best place. Basically, I'm using
    @JvmName
    annotations on a lot of my properties in interfaces. Now, this isn't an issue for the most part, except for the very frustrating and ridiculous inapplicable JVM name error that has to be suppressed in every class, but that's not the point of this. When I implement this interface, I would expect that those
    @JvmName
    named functions would be overridden in the Java code, however this is not the case. What I actually find is that the compiler will generate the property as normal, and then generate normal getters and setters, and make the overridden function a synthetic bridge method that delegates to the getter. Now, here's an example:
    interface Vehicle {
    
        @get:JvmName("wheels")
        val wheels: Int
    }
    data class Car(override val wheels: Int) : Vehicle
    And the generated code for this ends up looking something like this:
    public interface Vehicle {
    
        @JvmName(
            name = "wheels"
        )
        int wheels();
    }
    public final class Car {
    
        private final int wheels;
    
        public Car(int wheels) {
            this.wheels = wheels;
        }
    
        public int getWheels() {
            return wheels;
        }
    
        // $FF: synthetic method
        // $FF: bridge method
        public int wheels() {
            return getWheels();
        }
    }
    I am unsure if this is intended behaviour or not, but to me it seems counter-intuitive.
    e
    • 2
    • 1
  • d

    davidkarlsen

    09/26/2021, 10:22 PM
    any idea when kotlin will allow for jdk 17 as target?
    z
    • 2
    • 3
  • w

    William Reed

    09/28/2021, 2:02 PM
    is it correct that kotlin metadata does not contain information about other annotations? do I need to fall back to the java
    TypeElement
    for this information? if this is correct are there any libraries that wrap both in a kotlin idiomatic library?
    b
    • 2
    • 2
  • r

    rahulc29

    09/28/2021, 2:19 PM
    message has been deleted
    e
    • 2
    • 1
  • m

    mikehearn

    09/29/2021, 2:50 PM
    Rahul, I just commented on that bug. I think there's no reason it can't be used for everything, without any backwards compatibility breaks.
    e
    • 2
    • 1
  • z

    Zac Sweers

    10/04/2021, 3:24 AM
    FYI it appears that setting
    kotlinOptions.modulePath
    in an android project breaks incremental compilation. I've reproduced it and filed a bug here https://youtrack.jetbrains.com/issue/KT-49066
    :thank-you: 2
    • 1
    • 1
  • m

    Matej Drobnič

    10/04/2021, 7:16 AM
    Can anyone tell me what does
    Non-incremental compilation will be performed: NO_BUILD_HISTORY
    mean in kotlin build report? Occasionally build will take a long time (obviously non-incremental) and looking at the build report will produce above message. I have not cleaned the build folder or did anything similar (just normal run command while developing). How would I go about debugging what causes build history to get wiped?
    b
    a
    • 3
    • 9
  • d

    Daniel Svensson

    10/05/2021, 12:25 PM
    Is there any plans on adding interface delegation to value classes, fully compiled away?
    @JvmInline value class Foo(val b: Iface): Iface by b; fun bar(b: Iface) { ... }; val foo = Foo(..); bar(foo) // no boxing
    ?
    b
    i
    • 3
    • 2
  • r

    raulraja

    10/08/2021, 12:00 PM
    Hi, is there a branch or fork of the Kotlin compiler where the https://github.com/Kotlin/KEEP/issues/259 prototype is happening? I would like to take a look at it to see how we could model some new features we have in the works for Arrow. Thanks!
    d
    • 2
    • 2
  • r

    Rob Elliot

    10/08/2021, 2:36 PM
    Anyone know why you can’t have bounds on type alias parameters? I was trying to do this:
    typealias Fact<T : Any> = Pair<FactName, T>
    in order to ensure that you can’t put null in it, but no dice.
    e
    f
    • 3
    • 2
  • t

    Tomasz Krakowiak

    10/09/2021, 8:01 AM
    I am getting:
    java.lang.IllegalStateException: Not found Idx for public house.boardgames.model.cursor/CursorQuery|null[0]
    Obviously a bug in compiler, but as project is not open source I am trying to figure out the issue and create mve. So far unsuccessful, If you have any hint what may be causing it, I would be grateful. Details in the thread. Affected version: 1.5.30, 1.5.31 Works in: 1.5.21 (Unable to test 1.6.00-M1)
    a
    • 2
    • 7
  • c

    Callum Seabrook

    10/09/2021, 11:20 AM
    Anyone know if it would be possible to create a compiler plugin that could automatically apply
    JvmName
    annotations to getters, or better yet, just rename the getters itself?
    m
    • 2
    • 2
  • t

    Tomasz Krakowiak

    10/10/2021, 6:42 AM
    btw. Why is kotlin comiler distributed as single jar with dependencies (note - there is also dummy sources artifact distributed to maven, without any actual sources)
    j
    • 2
    • 2
  • e

    elect

    10/10/2021, 7:42 PM
    I'd like to delegate to some automation some additional code in order to dispose efficiently some resources which do not escape the scope of a function, that is they are local to the function. Annotation processor seems to be able to only generate new source code.. would a compiler plugin be able to modify existing source code instead?
    r
    e
    • 3
    • 6
  • d

    david.bilik

    10/12/2021, 7:43 AM
    Hi 👋 I’ve enabled
    kotlinOptions {
       allWarningsAsErrors = true    
    }
    in my gradle android project and it works as expected but unfortunately one library is generating code through kapt which has warnings and then my project does not compile. Is there a way to disable checks for specific warnings or to not check the generated code?
    e
    • 2
    • 2
  • j

    jimn

    10/12/2021, 6:55 PM
    how do we spoof a primitive int into a
    val foo:(Int)->Int
    in kotlin-jvm to squash boxing?
    e
    • 2
    • 5
  • p

    Petter Måhlén

    10/15/2021, 11:22 AM
    i ran into this type-inference problem, which i’m not sure how to think about. an example:
    class Container<T>(
        val func: (T) -> Unit,
        val aT: T
    )
    
    sealed class Foo {
        object Bar : Foo()
        object Baz : Foo()
    }
    
    fun main() {
        val c = Container(
            { f: Foo -> print("Got $f")},
            Foo.Bar
        )
    
        c.func(Foo.Baz) // doesn't compile, because c is Container<Foo.Bar>, not Container<Foo>
    
        val c2 = Container(
            { f: Foo -> print("Got $f")},
            Foo.Bar as Foo
        )
    
        c2.func(Foo.Baz) // compiles
    }
    so, the compiler infers
    c
    to be of type
    Container<Foo.Bar>
    , where I expected to get a
    Container<Foo>
    . It seems to me that there are two possible choices - either use
    Foo
    for type parameter
    T
    , or use the fact that since
    f
    accepts a
    Foo
    , it can also accept all `Foo.Bar`s. But what I wanted was in fact the former (the real use case is complicated by me trying to implement a typesafe heterogenous map of sorts, so I didn’t even get a compilation error, just a runtime ClassCastException). It seems to me like the current behaviour might be surprising - is there a reason for it, is it somehow more correct?
    d
    e
    +2
    • 5
    • 6
  • r

    raulraja

    10/15/2021, 1:56 PM
    Hello everyone, I have currently a use case to find all descriptors in the classpath annotated with a custom annotation. To implement this search I’m currently using a function that recursively walks all class path packages https://github.com/arrow-kt/arrow-meta/blob/883d4810ec37c57435d1a6a367368fb240030b[…]analysis/phases/analysis/solver/collect/ConstraintCollection.kt Here, I’m scanning each package and its subpackages recursively looking for the annotation on one of the child descriptors. This is extremely slow and incurs in a considerable startup time for plugins when the classpath is too big. Is there a way to retrieve a list of annotated descriptors from the classpath without recursively walking all packages like this? thank you!
    f
    c
    +5
    • 8
    • 12
Powered by Linen
Title
r

raulraja

10/15/2021, 1:56 PM
Hello everyone, I have currently a use case to find all descriptors in the classpath annotated with a custom annotation. To implement this search I’m currently using a function that recursively walks all class path packages https://github.com/arrow-kt/arrow-meta/blob/883d4810ec37c57435d1a6a367368fb240030b[…]analysis/phases/analysis/solver/collect/ConstraintCollection.kt Here, I’m scanning each package and its subpackages recursively looking for the annotation on one of the child descriptors. This is extremely slow and incurs in a considerable startup time for plugins when the classpath is too big. Is there a way to retrieve a list of annotated descriptors from the classpath without recursively walking all packages like this? thank you!
f

Fleshgrinder

10/15/2021, 3:15 PM
The reflections library can do this fast.
👀 1
c

christophsturm

10/15/2021, 3:26 PM
i think classgraph is the fastest.
👍 1
but classpath scanning is never fast
f

Fleshgrinder

10/15/2021, 3:38 PM
Or maybe the new JetBrains plugin is usable for you: https://kotlinlang.slack.com/archives/C7L3JB43G/p1631889133070500
e

elect

10/15/2021, 4:20 PM
+1 for classgraph, although I'm not sure it can be useful for your specific conditions
r

ralf

10/15/2021, 4:47 PM
In regards to compiler plugins what I did is generating a hint in a specific package each time someone is using the annotation. Then the scanner only has to read the generated hints instead of scanning the entire classpath. Maybe that’s an option.
s

shikasd

10/15/2021, 6:07 PM
+1 for hint, generating a dummy class/file linking to symbols worked for me
r

raulraja

10/15/2021, 6:25 PM
thanks everyone for all the suggestion, we’ll check them out! 🙏
a

Alejandro Serrano Mena

10/15/2021, 7:19 PM
thanks for all your help! @ralf do you happen to have an example of how to encode those hints in a good way?
r

ralf

10/15/2021, 7:20 PM
Real world example: https://github.com/square/anvil/blob/main/compiler/src/main/java/com/squareup/anvil/compiler/codegen/ContributesToGenerator.kt
a

Alejandro Serrano Mena

10/15/2021, 7:21 PM
awesome! :thank-you:
a

Anastasia Birillo [JB]

10/19/2021, 5:52 PM
Yes, if all information is known at the compile time you can use the Reflekt plugin, we will release a version that supports incremental compilation in a couple of weeks (hope no more than after two). Our approach uses descriptors and scans the classpath at the compile time
View count: 9