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
  • r

    Rob Elliot

    01/30/2023, 10:20 AM
    I'm not sure how good an idea this is, but... A frustration of mine for ages has been the way you have to choose between compile time safety and convenience when constructing values into types - e.g. converting a
    String
    into a
    URI
    . For untrusted input ideally I want a function that forces the caller to handle the bad case -
    fun String.toUri(): Either<URISyntaxException, URI>
    . But that's a colossal pain when constructing from a string literal; I don't want
    "<http://www.example.com>".toUri()
    to return an
    Either
    , I want a
    URI
    ! Of course you can provide two methods, one for untrusted input, one for trusted, but that immediately opens up the possibility of human error choosing the wrong one. So I was wondering if a compiler plugin could actually infer that the function's arguments are known at compile time and actually call the function to prove that it returns a
    Right<URI>
    , and in that case allow
    val uri: URI = "<http://www.example.com>".toUri()
    to compile, and throw a compile error on
    val uri: URI = "not a uri".toUri()
    .
    w
    s
    • 3
    • 5
  • p

    PHondogo

    01/31/2023, 8:16 PM
    Hello! When switched to 1.8.0 from 1.7.0 invoking IrClass::isSublclassOf starts to return false for some cases in such expression:
    override fun visitClassNew(declaration: IrClass): IrStatement {
      declaration.isSubclassOf(pluginContext.referenceClass(FqName("a.b.c.InterfaceThatDeclarationHave"))!!.owner) // in 1.8.0 version start to return false
      ...
    }
    If declaration change to (pluginContext.referenceClass(declaration.fqNameWhenAvailable!!)!!.owner) then isSubclassOf return true.
    (pluginContext.referenceClass(declaration.fqNameWhenAvailable!!)!!.owner).isSubclassOf(pluginContext.referenceClass(FqName("a.b.c.InterfaceThatDeclarationHave"))!!.owner) // as an ugly workaround
    Is it a bug? If no, how should I work with class references now?
  • p

    PHondogo

    01/31/2023, 9:53 PM
    Anybody faced with 'java.lang.VerifyError: Bad local variable type' when run program compiled with Xdebug (Kotlin 1.8.0)?
    e
    • 2
    • 1
  • c

    Charlie Tapping

    02/01/2023, 3:08 PM
    Hello 😒imple_smile: I’m thinking of building a compiler plugin for a small library I’m working work on, but I’d like to understand if what I want to do is feasible . Essentially I would want to find all the callsites of a particular function, say.
    Example.foo(x: Any)
    Then for every given different type of x, I would need to add an implementation for a interface to that type. The interface basically encodes the type to and from a hashmap by iterating all of the properties in the class recursively, turning the object into a HashMap<String, String> For example if you called:
    Example.foo(user: User)
    and
    data class User(
    private val name: String,
    private val age: Int
    )
    I would generate
    data class User(
    private val name: String,
    private val age: Int
    ) : Adapter {
    fun fromHashmap() {
    ...
    }
    fun toHashmap() {
    ...
    }
    }
    Is this possible? Any help would be greatly appreciated!
    n
    p
    • 3
    • 3
  • u

    ursus

    02/06/2023, 11:58 PM
    As a android developer that only writes kotlin code. what
    jvmTarget
    should I use? Is there anything to gain when bumping ˙1.8` to
    11
    , when java language features are irrelevant to me? Performance?
    e
    j
    • 3
    • 138
  • j

    jw

    02/07/2023, 4:05 AM
    How do I return an integer constant created via
    <http://IrConstImpl.int|IrConstImpl.int>
    from a
    Function0<Int>
    lambda/local function that i've created?
    y
    s
    • 3
    • 16
  • m

    mcpiroman

    02/07/2023, 1:19 PM
    May I ask what is the reasoning of language version 2.0 (apparently instead of 1.10) as introduced here? Is it a final decision? It seems to be related specifically to K2, but AFAIK it does not change the language significantly. I.e. there aren't differences that would justify distinction between Kotlin 1 and Kotlin 2, as it is in say python 2 vs python 3, right?
    d
    r
    • 3
    • 3
  • t

    Tracey Yoshima

    02/07/2023, 11:49 PM
    Hi! I’m curious if there is a Kotlin compiler configuration that preserves some of the structure in a PSI in the FIR or a means to visit the PSI and associate the PSI to the FIR:
    d
    • 2
    • 4
  • q

    Quantum64

    02/09/2023, 7:57 PM
    With FIR now having a release timeline, have there been any internal discussions on expression transformation APIs? Just don't want that to be forgotten about 🙂
    d
    • 2
    • 1
  • t

    Travis Griggs

    02/13/2023, 9:41 PM
    What is the current idiomatic method to apply
    @kotlin.ExperimentalUnsignedTypes
    globally to a whole project, so I don't have to annotate 500+ sites? I had this with gradle compiler options once upon a time, but I think that's evolved and the names may have changed since then (sorry if this belongs in another channel, please direct if so?)
    a
    b
    • 3
    • 7
  • r

    ralf

    02/14/2023, 12:48 AM
    How do you attach the debugger to the Kotlin compiler with 1.8.20? In the past I used
    -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy=in-process
    But with 1.8.20 you can’t run the compiler in-process anymore. In other tickets I found
    -Dkotlin.daemon.jvm.options="-agentlib:jdwp=transport=dt_socket\,server=y\,suspend=n\,address=*:5005"
    But no luck there, the connection is refused. Any advice?
    • 1
    • 1
  • o

    Olaf Gottschalk

    02/14/2023, 4:44 PM
    I am not really sure if this channel is correct for my question... I am having big difficulties understand an inferred type in a sealed class (abstract also does not work) hierarchy with a generic type in the base type... If I am not in the right channel, please excuse me asking here... 😉
    sealed class Blah<T> {
        abstract fun doSomething(): T
        abstract fun doAnotherThing(a: T)
    }
    
    object A : Blah<Int>() {
        override fun doSomething(): Int = 42
        override fun doAnotherThing(a: Int) {}
    }
    
    object B : Blah<String>() {
        override fun doSomething(): String = "42"
        override fun doAnotherThing(a: String) {}
    }
    
    // inferred type is Blah<out Any>
    fun gimmeBlah() = if (Random.nextBoolean()) A else B
    // error is Type mismatch. Required: Blah<Any?> Found: A
    fun doesNotCompile(): Blah<Any?> = if (Random.nextBoolean()) A else B
    I do NOT understand, why the inferred type introduces the "out" variance.... it does not make sense to me (and does not work in my context....)
    a
    • 2
    • 3
  • e

    eygraber

    02/14/2023, 6:25 PM
    Is there a way to have a union of
    protected
    and
    internal
    visibility? Pretty sure the answer is no, but just checking. Are there any proposals for adding something like that? Use case is where I want to invoke an abstract function from a class in the same module, and have subclasses implement them.
    a
    e
    y
    • 4
    • 4
  • c

    Charlie Tapping

    02/17/2023, 2:43 PM
    Does anyone know why Given an interface like:
    interface SynkAdapter<T : Any> : IDResolver<T>, MapEncoder<T>
    An impl like this does not count as the aggregated type (SynkAdapter)
    class FooSynkAdapter(
        private val fooResolver: IDResolver<Foo> = FooResolver(),
        private val fooMapEncoder: MapEncoder<Foo> = FooMapEncoder()
    ) : IDResolver<Foo> by fooResolver, MapEncoder<Foo> by fooMapEncoder
    You have to do this??
    class FooSynkAdapter(
        private val fooResolver: IDResolver<Foo> = FooResolver(),
        private val fooMapEncoder: MapEncoder<Foo> = FooMapEncoder()
    ) : SynkAdapter<Foo>, IDResolver<Foo> by fooResolver, MapEncoder<Foo> by fooMapEncoder
    Surely if an interface is just a union of two other interfaces then implementing those interfaces should make it compatible? I’m sure there must be a good reason for having to be explicit?
    s
    v
    • 3
    • 15
  • j

    juliocbcotta

    02/21/2023, 2:45 PM
    Hey, I am trying to update my android project from kotlin 1.7.21 to 1.8.10 and I am getting these warnings for dependencies and my modules too...
    ...
    e: /Users/julio.buenocotta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.10/6d5560a229477df9406943d5feda5618e98eb64c/kotlin-stdlib-1.8.10.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
    e: /Users/julio.buenocotta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.10/6d5560a229
    Any pointers? I googled it and couldn't find anything that would fix it for me. Thanks
    a
    • 2
    • 5
  • l

    louiscad

    02/21/2023, 4:41 PM
    Can we get an interpreted mode for Kotlin? 🙏🏼 https://twitter.com/ablenessy/status/1626570080094920705
    z
    e
    +5
    • 8
    • 62
  • d

    Danil

    02/23/2023, 9:36 AM
    Hi! Is there anyone here who can help with the Koltin compiler API? In short, I would like to compile Kotlin code from string to string in JS using K2 or IR compiler And I would like to know if it is possible to compile each Kotlin file into a separate JS file with separate type definitions and source map..
  • n

    napperley

    02/24/2023, 10:26 PM
    A mod in #meta recommended this channel after I asked if there was a channel that covered porting Kotlin to new platforms. Currently I have made some changes to a forked Kotlin code base ( https://github.com/napperley/kotlin/tree/rp2040 ) to add rp2040 ( https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html ) as an unofficial Kotlin target. Some key things are missing that I want to sort out which include the following: • Connecting the official ARM GNU tool chain ( https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain ; GCC based & uses Newlib Standard library ) to the code base (incl sysroot and other important paths that the code base requires) • Forcing the Kotlin compiler to omit the linking step and only generate a static library file for the rp2040 target • Figure out what is meant by configurables and supply the necessary stuff that is relevant to the rp2040 target When building the Kotlin code base an error appears about a unresolved JDK 7 dependency (some attempts are made to fetch the dependency from a Space server). As an added bonus I would like to automate the entire build via Gradle for the rp2040 target if possible, although that may not be feasible since the Raspberry Pi Pico SDK ( https://github.com/raspberrypi/pico-sdk ; also covers uC's that use the RP2040 uC chip ) uses CMake for generating a heavily optimized binary (via a tool provided by the SDK) from a static library file.
    a
    • 2
    • 3
  • a

    Akshit Sinha

    02/25/2023, 5:30 PM
    I'm trying to compile the Kotlin compiler using
    gradlew dist
    but getting this error. Any idea what might be the cause? Is it the JDK version or something?
    n
    • 2
    • 2
  • v

    vladimirsitnikov

    02/27/2023, 9:24 AM
    I’ve released https://github.com/vlsi/kotlin-argument-expression plugin that captures and passes call argument expression to the downstream function. For instance:
    class Named<Value>(
        val value: Value,
        @CallerArgumentExpression("value") val name: String = ""
    ) {
        override fun toString(): String = "Named(value=$value, name='$name')"
    }
    
    Named(2+2) // the plugin would transform the call to Named(2+2, "2+2")
    It might be helpful for tests, preconditions, asserts, etc, so you can have better outputs with almost no overhead.
    e
    • 2
    • 4
  • n

    napperley

    02/27/2023, 11:08 PM
    Numerous error messages are appearing about unresolved references after running the following:
    ./gradlew :kotlin-native:dist
    Many of these references already exist in the Kotlin fork, and should be picked up during the compilation process. Below is one of the error messages:
    kotlin/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt:201:24 Unresolved reference: RP2040
    The reference referred to in the error message above exists in this file: https://github.com/napperley/kotlin/blob/rp2040/native/utils/src/org/jetbrains/kotlin/konan/target/KonanTarget.kt#L35
    • 1
    • 4
  • n

    napperley

    03/02/2023, 1:58 AM
    Since there is no issue in the Issue Tracker on providing a guide for porting Kotlin to new platforms I tried to create a new issue, however the Issue Tracker is currently in read only mode 😦.
    e
    • 2
    • 2
  • a

    Amejonah 1200

    03/02/2023, 4:56 PM
    Hello o/ Is K2 in its own branch or is it the master one? How to contribute to K2 and not the old one? How is Kotlin 1.8.20 developed in the same time as 1.9 and K2? How should I start with the project?
    d
    n
    • 3
    • 12
  • n

    napperley

    03/03/2023, 12:20 AM
    Is there anything I should know about the :kotlin-native-shared:compileKotlin Gradle task? How does this Gradle task work when the source files are scattered all over the place? As an example a new Family (BARE_METAL) is defined in Family.kt. During the build process the :compile-kotlin task fails. Some fixes are made and the task complete successfully. On another run of the build process the :kotlin-native-shared:compileKotlin task (next task after :compile-kotlin) fails with some errors on unresolved references to
    Family.BARE_METAL
    . Nothing can be done to fix the issue since it isn't known how references are resolved/handled with the :kotlin-native-shared:compileKotlin task, even though it is processing some of the same source files as the :compile-kotlin task.
    • 1
    • 1
  • s

    Sebastian Schuberth

    03/03/2023, 2:59 PM
    Does anyone know of a compiler plugin that can create a nullable version of a data class where the original properties are nullable?
  • n

    Nivaldo H Bondança

    03/03/2023, 3:45 PM
    Colored compiler error output Does anyone know if kotlinc support colored compiler errors, or if there's an open issue regarding it? They are entirely red and hard to read as-is. Here's an example of what I had in mind (and also showing there's precedence for this)
    j
    s
    • 3
    • 4
  • t

    Thiago

    03/03/2023, 6:44 PM
    Hi folks, Is Kotlin Incremental compilation a behavior specific to build tools as IDEA internal build system or Gradle? If I am developing Kotlin things without IDEA and Gradle, will
    kotlinc
    create ABI Snapshot for my files?
    s
    m
    • 3
    • 3
  • n

    napperley

    03/04/2023, 4:52 AM
    An issue (feature request) has been created about a Kotlin Targets plugin system: https://youtrack.jetbrains.com/issue/KT-57111/Provide-Kotlin-Targets-Plugin-System
  • s

    sdeleuze

    03/04/2023, 1:11 PM
    If there is enough visibility, could somebody from JetBrains comment on https://github.com/gradle/gradle/issues/21284 an approximate ETA for being able to use K2 with the scripting support which is required for Gradle?
    i
    • 2
    • 1
  • j

    johnaqel

    03/06/2023, 2:14 AM
    Hi folks, does anyone know if an AOP Kotlin compiler plugin exists? Something like AspectJ but for Kotlin. Has anybody been working on this?
    e
    • 2
    • 3
Powered by Linen
Title
j

johnaqel

03/06/2023, 2:14 AM
Hi folks, does anyone know if an AOP Kotlin compiler plugin exists? Something like AspectJ but for Kotlin. Has anybody been working on this?
e

ephemient

03/06/2023, 3:15 AM
for some purposes, you can consider using built-in Kotlin functionality instead of AOP: https://elizarov.medium.com/aop-vs-functions-2dc66ae3c260
but there aren't any general AOP frameworks for Kotlin as far as I know
j

johnaqel

03/06/2023, 4:21 AM
Thank you @ephemient. I had read that article before. But yeah, looking for an annotation based solution.
View count: 10