https://kotlinlang.org logo
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
  • t

    Tomasz Krakowiak

    12/06/2021, 9:00 AM
    I have strange issue. I wonder how to troubleshoot. "e: Could not find "pro.streem.pbandk:runtime" in [C:\Users\Niema\AppData\Local\kotlin\daemon]". Stacktrace in thread.
    • 1
    • 2
  • m

    max.kammerer

    12/08/2021, 10:45 AM
    We are going to switch Kotlin compiler build from
    -Xjvm-default=disable
    mode to
    -Xjvm-default=all
    . This change will keep source compatibility but could break binary one if you are using compiler internals. If you use some compiler internal interfaces could you please list them in thread. In such case we will try to also ship binary compatible stubs for
    DefaultImpls
    classes (that would gone away in
    all
    mode) UPD: this post is not about switching default value for
    -Xjvm-default
    . The aim of it to avoid any occasional breakage for compiler extension, plugins
    👀 1
    m
    r
    • 3
    • 11
  • t

    Thiago

    12/08/2021, 2:58 PM
    Why compiler warning me to avoid
    a > 0 && a < 10
    and replace with range as
    a in 1..9
    ? Why "primitive" comparisons are not recommended in favor of Ranges instances to call a contains operator? Is there any article/resources explaining the recomendation?
    d
    f
    +2
    • 5
    • 9
  • a

    Alex

    12/10/2021, 9:09 AM
    I'm getting the following after upgrading from kotlin 1.5.31 to 1.6.0... did anyone ever encounter something similar and can help me out here?
    java.lang.IllegalStateException: Symbol for kotlin.collections/mutableMapOf|-4813910536206556932[0] is unbound
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindablePublicSymbolBase.getOwner(IrPublicSymbolBase.kt:52)
    ...
    n
    • 2
    • 5
  • c

    Carl Hickman

    12/10/2021, 5:42 PM
    Is there some tooling that will produce an abstract syntax tree for an app written in Kotlin? There is some static analysis that I would like to do to check for custom patterns in my code base.
    👀 1
    p
    j
    c
    • 4
    • 7
  • r

    Roshad Guerrier

    12/14/2021, 11:20 PM
    Can anyone help me? I’m on a Macbook so I end up using z-shell but the problem still occurs when I use bash. I’m trying to run Kotlin/Native using the command-line compiler but I get an error saying kotlin-native command cannot be found. I’ve installed the compiler but still get the error.
    e
    e
    • 3
    • 21
  • e

    Exerosis

    12/17/2021, 8:30 PM
    Hey does anyone know if the compiler can optimize away things like this: if (x in (firstContainer + secondContainer)) to avoid creating a new container?
    d
    r
    +2
    • 5
    • 6
  • z

    Zac Sweers

    12/17/2021, 10:14 PM
    has anyone written an IR plugin that creates new IrFiles? The examples I’ve seen seem to focus on manipulating existing code but not necessarily generating new top-level classes. Curious how others are approaching this
    y
    • 2
    • 17
  • h

    holgerbrandl

    12/18/2021, 11:25 AM
    Hi, is there some documentation about the benefits of using a more recent jvm target than the default (which is 1.8 I believe)? E.g. what's getting better when using
    kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
    in my grade build definition?
    ➕ 3
    j
    • 2
    • 1
  • a

    Andy Himberger

    12/20/2021, 4:59 AM
    Seeing this error upgrading from 1.5.31 to 1.6 or 1.6.10 in our compose enable module, I saw @nschulzke also hit this and suggested reviewing use of mutableMapOf, I have no uses of mutableMapOf, and I'm not using the one thing in compose itself I see with a call to mutableMapOf, other suggestions on how to track it down?
    java.lang.IllegalStateException: Symbol for kotlin.collections/mutableMapOf|-4813910536206556932[0] is unbound
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindablePublicSymbolBase.getOwner(IrPublicSymbolBase.kt:52)
    	at org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl.getOwner(IrPublicSymbolBase.kt:74)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitCall(LiveLiteralTransformer.kt:663)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:199)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:24)
    	at org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl.accept(IrCallImpl.kt:47)
    	at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:33)
    	at org.jetbrains.kotlin.ir.expressions.IrExpressionBody.transformChildren(IrBody.kt:46)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBody(IrElementTransformerVoid.kt:108)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitExpressionBody(IrElementTransformerVoid.kt:114)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitExpressionBody(IrElementTransformerVoid.kt:115)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitExpressionBody(IrElementTransformerVoid.kt:24)
    	at org.jetbrains.kotlin.ir.expressions.IrExpressionBody.accept(IrBody.kt:36)
    	at org.jetbrains.kotlin.ir.expressions.IrExpressionBody.transform(IrBody.kt:39)
    	at org.jetbrains.kotlin.ir.declarations.IrField.transformChildren(IrField.kt:41)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElementTransformerVoid.kt:57)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitField(IrElementTransformerVoid.kt:81)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitField(IrElementTransformerVoid.kt:82)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitField(IrElementTransformerVoid.kt:24)
    	at org.jetbrains.kotlin.ir.declarations.IrField.accept(IrField.kt:34)
    	at org.jetbrains.kotlin.ir.IrElement$DefaultImpls.transform(IrElement.kt:32)
    	at org.jetbrains.kotlin.ir.IrElementBase.transform(IrElementBase.kt:19)
    	at org.jetbrains.kotlin.ir.util.TransformKt.transformInPlace(transform.kt:35)
    	at org.jetbrains.kotlin.ir.declarations.IrClass.transformChildren(IrClass.kt:66)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElementTransformerVoid.kt:57)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:66)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$visitClass$s780614737(LiveLiteralTransformer.kt:158)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitClass$1.invoke(LiveLiteralTransformer.kt:466)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitClass$1.invoke(LiveLiteralTransformer.kt:465)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:117)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor$siblings$1.invoke(DurableKeyVisitor.kt:131)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:131)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.siblings(LiveLiteralTransformer.kt:194)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitClass(LiveLiteralTransformer.kt:465)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:67)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:24)
    	at org.jetbrains.kotlin.ir.declarations.IrClass.accept(IrClass.kt:55)
    	at org.jetbrains.kotlin.ir.IrElement$DefaultImpls.transform(IrElement.kt:32)
    	at org.jetbrains.kotlin.ir.IrElementBase.transform(IrElementBase.kt:19)
    	at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.transformChildren(IrFileImpl.kt:89)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitPackageFragment(IrElementTransformerVoid.kt:41)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:47)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$visitFile$s780614737(LiveLiteralTransformer.kt:158)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitFile$1.invoke(LiveLiteralTransformer.kt:549)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitFile$1.invoke(LiveLiteralTransformer.kt:479)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:117)
    	at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.root(DurableKeyVisitor.kt:152)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitFile(LiveLiteralTransformer.kt:479)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:48)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:24)
    	at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.accept(IrFileImpl.kt:81)
    	at org.jetbrains.kotlin.ir.declarations.IrFile.transform(IrFile.kt:52)
    	at org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl.transformChildren(IrModuleFragmentImpl.kt:45)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:330)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.lower(LiveLiteralTransformer.kt:171)
    	at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:96)
    	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr$lambda-1(JvmIrCodegenFactory.kt:121)
    	at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:88)
    	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:146)
    	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr$default(JvmIrCodegenFactory.kt:64)
    	at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:59)
    	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:331)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:123)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:170)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:434)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:120)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:357)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:299)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl$rebuild(IncrementalCompilerRunner.kt:118)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:169)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:80)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:622)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:100)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1713)
    	at jdk.internal.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    b
    r
    • 3
    • 6
  • p

    PHondogo

    12/21/2021, 10:10 AM
    Hello! This code is not compiling:
    var b : Byte = 10.toByte()
    b += 10.toByte()
    Complains about type mismatch: Required Byte got Int. Why?
    e
    e
    • 3
    • 3
  • m

    martmists

    12/23/2021, 10:33 PM
    Given an IrFunction, how do I check if it's an operator function?
    l
    • 2
    • 1
  • m

    martmists

    12/25/2021, 6:34 PM
    What's the recommended way to generate large amounts of IR for native using a compiler plugin?
    y
    • 2
    • 9
  • u

    ursus

    12/26/2021, 3:03 PM
    I wrote a custom compiler and
    gradlew clean
    fails on windows due to files being locked, but works on linux/mac https://github.com/square/anvil/issues/458#issue-1088683292 any ideas?
    j
    • 2
    • 3
  • c

    Chachako

    12/28/2021, 2:59 PM
    Hi guys! I am writing a Kotlin compiler plugin. I want to find all specific references and replace them at compile time. Is there an API that can help me get there quickly? At present, my idea is to use
    IrGenerationExtension
    to process all files, then access all expressions through
    IrElementTransformer
    , then find out the corresponding references and replace them, but I’m a little worried about its performance. I would be grateful if someone could give me a some advice! 🙏🏻
    m
    • 2
    • 5
  • c

    Chachako

    12/29/2021, 3:00 PM
    Is there a way to smart cast the type of expressions through the compiler plugin? I noticed a
    SmartCastManager
    at the compiler-frontend, but I don’t know how to start. I want to smart cast type after an expression, for example:
    class CallBlock(private val types: KClass<*>) {
      fun resultAt(index: Int): Any = results[index]
    }
    
    fun call(vararg types: KClass<*>, block: CallBlock.() -> Unit) = ...
    
    call(Int::class, String::class) {
      val a = resultAt(0) // Implicit: Int
      val b = resultAt(1) // Implicit: String
    }
    --- As shown in the code, I want to smart cast the type result of
    resultAt()
    call
    d
    • 2
    • 5
  • y

    Youssef Shoaib [MOD]

    12/31/2021, 2:38 AM
    This is more of a gradle question, but it's really specific to compiler development How can I bootstrap my compiler plugin? I tried to simply apply the plugin with a previous version (i.e. a version on maven central that isn't in my included buids) but gradle just blindly sees that the plugin artifact is in my included builds and simply uses it without looking at the version, which results in a circular dependency and my project not building. I can see some mentions of this in the kotlin compiler source itself, but I don't quite understands how it works. Is there just a simple fix to make it so that Gradle doesn't look for gradle plugins in included builds?
    d
    • 2
    • 5
  • p

    Piotr Krzemiński

    01/03/2022, 10:50 AM
    I recently stumbled upon this diagram of compiler architecture, so I thought I'll share a diagram of declared dependencies between lowerings, see the thread (in this particular case, it's for JS IR backend). It's a part of working on Python backend (https://github.com/krzema12/kotlin-python, #python). It can get out of date quickly, so long-term it would be best to have it auto-generated. The code responsible for generating it is for now here in a GitHub issue. Should be easy to adapt for JVM or any other backend
    👏 3
    m
    • 2
    • 3
  • c

    Craig

    01/03/2022, 10:00 PM
    Is it possible to modify the frontend ast without writing it back to the source file? I'm writing a new runtime for jetpack compose (a la mosaic and Compose for Desktop) and want to automatically (and invisibly to the developer) add @Composable annotations by convention. This has to happen before
    ComposableCallChecker
    runs, which I think means it needs to happen in the frontend. I tried this is in a
    AnalysisHandlerExtension
    myKtNamedFunction.addAnnotationEntry(KtPsiFactory(project).createAnnotationEntry("@androidx.compose.runtime.Composable"))
    but it throws "Cannot modify a read-only file 'main.kt'"
    k
    m
    +2
    • 5
    • 10
  • c

    Chachako

    01/05/2022, 3:20 PM
    Is there a way to evaluate expression to constant value in IR? There is a
    ConstantExpressionEvaluator
    in the frontend. Is there something similar in the backend?
    r
    y
    +2
    • 5
    • 18
  • r

    Rob Elliot

    01/05/2022, 4:13 PM
    In this thread https://kotlinlang.slack.com/archives/C0B8MA7FA/p1641395257152000?thread_ts=1641388216.147600&amp;cid=C0B8MA7FA I was intrigued to discover that the compiler will already implicitly treat a type parameter
    <T>
    as
    <T & Any>
    in some circumstances if you also use it as
    <T?>
    .
    y
    • 2
    • 3
  • r

    Rob Elliot

    01/06/2022, 1:38 PM
    Just out of interest - back in the days when Kotlin was first designed was there any discussion about making covariant generic types the default, with invariant & contravariant requiring extra syntax? My gut feel is that most people expect
    Foo<String>
    to be a subtype of
    Foo<Any>
    , and if you favour immutable data types then covariance often Just Works™. I try and remember to use
    <out T>
    as my starting point, until I need something else, but I often forget...
    e
    • 2
    • 2
  • s

    server

    01/10/2022, 6:44 AM
    can I somehow convert IrClass to PsiClass?
    d
    s
    • 3
    • 11
  • r

    Rob Elliot

    01/10/2022, 3:11 PM
    The https://github.com/bnorm/kotlin-power-assert plugin mentioned above made me wonder if anyone's gone as far as implementing Spock's
    then
    blocks in a compiler plugin? I still really miss the sheer simplicity of the syntax of Spock's tests.
    👍 2
    c
    j
    +4
    • 7
    • 59
  • a

    andylamax

    01/11/2022, 5:35 AM
    Hello folks, I have upgraded to kotlin 1.6.10 and I am getting weird errors from the compiler. Kotlin/Js compiler to be exact. It seems to be looking for dependencies in ~/.local/share/kotlin/daemon I have
    Could not find "kotlin" in [/home/andylamax/.local/share/kotlin/daemon]
    and previously I also had
    Could not find "kotlinx-serialization-core" in [/home/andylamax/.local/share/kotlin/daemon]
    Has anyone come across this? or better yet, found a solution to this??
    ➕ 1
    h
    • 2
    • 1
  • j

    jianbing

    01/11/2022, 2:52 PM
    I had met problem hope this channel can help me out... I am using Kotlin few months ago and I have the kotlinc compiler plugin (using arrow meta library) in place which changes the .class by adding, for example, new properties or new methods etc during kotlin compilation time. for example, the original source Kotlin A.kt is like below
    @MetaData
    data class A (val x: String, val y: String)
    after applying compiler plugin, the .class file will be altered to something like below (from source perspective), basically, I will add implicitly MetaData into the primary constructor for all source Kotlin so long as it is with annonation @MetaData in place, plus a new method 
    fun getMetaData()
     get generated.
    data class A(val x: String, val y:String, val myMeta: MetaData) {
           fun getMetaData() {
             //some logic check
             return myMeta
           }
        }
    now when it comes to use the new synthetic ".class" file manipulated as below, IntelliJ complains it cannot find resolve A (it has only the constructor with 2 parameters not 3) and cannot resolve the the synthetic method getMetaData() either.
    val x = A("ba", "fo", MetaData(..))
    val y = x.getMetaData()
    can somebody shed some light on it? I know lombok seems no problem with it after adding its @Getter annotation for example into Java source code, IntelliJ can recognize its getXXX method (which is generated by lombok). I don't know how to implement the same for my case for kotlin language. please include the detailed steps if possible.
    :stackoverflow: 1
    👀 1
    r
    c
    • 3
    • 9
  • p

    PHondogo

    01/12/2022, 1:30 PM
    Hello! Does Kotlin class/field metadata changed in 1.6 version? After updating from 1.5.31 to 1.6.10 in case of using proguard (even with dontshrink and dontobfuscate) KType::isMarkedNullable is false for nullable fields.
    e
    • 2
    • 2
  • c

    Chachako

    01/12/2022, 5:58 PM
    Hi everyone, why is this problem and how can I solve it? I just called
    IrModuleFragment.transformChildrenVoid
    🤯
    * What went wrong:
    Execution failed for task ':api:compileKotlinJvm'.
    > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
       > Internal compiler error. See log for more details
    
    e: java.util.ConcurrentModificationException
    	at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)
    	at java.base/java.util.ArrayList$Itr.next(ArrayList.java:997)
    	at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.transformChildren(IrFileImpl.kt:97)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitPackageFragment(IrElementTransformerVoid.kt:41)
        ......
    	at org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl.transformChildren(IrModuleFragmentImpl.kt:45)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:330)
    	at com.meowool.sweekt.lazyinit.LazyInitTransformer.lower(LazyInitTransformer.kt:73)
    	at com.meowool.sweekt.SweektComponentRegistrar$registerProjectComponents$1.generate(SweektCompilerPlugin.kt:86)
    • 1
    • 2
  • s

    Sasha Shpota

    01/12/2022, 8:22 PM
    Hi everybody, I have a question regarding Kotlin compiler plugin compatibility. Let's say, I have a plugin based on Kotlin 1.5 that uses APIs that would be removed in Kotlin 1.6 (for instance,
    IdSignature.PublicSignature
    was in 1.5, but is removed in 1.6). Will my plugin (built on 1.5) work with applications using Kotlin 1.6? And vice versa, let's say I update my plugin to use Kotlin 1.6, will the clients with 1.5 be able to use the plugin version based on 1.6? How should I handle such changes?
    p
    • 2
    • 1
  • s

    sindrenm

    01/13/2022, 4:17 PM
    Hi! Sorry if this is the wrong channel of if it's been asked before, but I just noticed smart-casts of
    (() -> Unit)?
    doesn't always allow calling in the “natural” way. Is this a known issue? (Kotlin 1.6.0.)
    d
    f
    b
    • 4
    • 15
Powered by Linen
Title
s

sindrenm

01/13/2022, 4:17 PM
Hi! Sorry if this is the wrong channel of if it's been asked before, but I just noticed smart-casts of
(() -> Unit)?
doesn't always allow calling in the “natural” way. Is this a known issue? (Kotlin 1.6.0.)
Here's the code in text, for simplicity:
class Runner(private val run: (() -> Unit)?) {
    fun works() {
        if (run == null) return

        run.invoke()
    }

    fun fails() {
        if (run == null) return

        run()
    }
}
Interestingly, it acts as expected if the lambda is not a class property, as this here works:
fun runner(run: (() -> Unit)?) {
    if (run == null) return

    run()
}
A playground link: https://pl.kotl.in/qPSCNha93
d

Dominaezzz

01/13/2022, 4:40 PM
seems like bug
f

Fleshgrinder

01/13/2022, 4:45 PM
This was always the case and is nothing new, so I wouldn't say bug. The compiler could probably be extended to support this, but there might be good reasons to not do it. 🤷 For your particular case this would work nicely as well:
run?.invoke() ?: return
d

Dominaezzz

01/13/2022, 4:57 PM
The
?
in your workaround is not needed, which is part of the issue.
f

Fleshgrinder

01/13/2022, 5:01 PM
The problem is that the compiler needs to insert the smart cast, in order for it to do so it needs it to be stand-alone. My guess is that the smart cast processing is done in the same iteration as the unsugaring of calls (don't quote me on that, I don't know) and that it requires an explicit call because of that.
fun f() {
    if (run == null) return
    run() // requires smart cast, but doesn't work in any Kotlin version because of operator sugar
}
The alternative I gave for the particular example would be:
fun f() {
    run?.invoke() ?: return
}
This would work in the example case, but not in the general case (obviously). A general solution to fix this:
fun f() {
    // snip
    run?.let { run ->
        // snip
        run()
        // snip
    }
    // snip
}
You can actually see the smart cast in the screenshot, look at the
works
function and the green background color of
run
.
d

Dominaezzz

01/13/2022, 5:02 PM
So why does the
works
compile?
f

Fleshgrinder

01/13/2022, 5:03 PM
Because it's not using any sugar, the
run.invoke()
in
works
gets transpiled to
(run as () -> Unit).invoke()
. (Well, smart casted.)
s

sindrenm

01/13/2022, 5:07 PM
But why would this work, then?
fun runner(run: (() -> Unit)?) {
    if (run == null) return

    run()
}
This is smart-cast + sugar, the only difference is we're dealing with a function parameter and not a class property:
b

bashor

01/13/2022, 5:25 PM
feel free to vote for https://youtrack.jetbrains.com/issue/KT-4113
👍 2
f

Fleshgrinder

01/13/2022, 5:25 PM
I really don't know and the generated bytecode (IntelliJ Kotlin tools) is equivalent too. 🤷
L2
    LINENUMBER 6 L2
    ALOAD 0
    GETFIELD Test.run : Lkotlin/jvm/functions/Function0;
    INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)
    POP
   L3
    LINENUMBER 7 L3
    ALOAD 0
    GETFIELD Test.run : Lkotlin/jvm/functions/Function0;
    INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)
    POP
   L4
    LINENUMBER 8 L4
    ALOAD 1
    INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)
    POP
   L5
    LINENUMBER 9 L5
    ALOAD 1
    INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)
    POP
✅ 1
Voted for the issue, very inconsistent behavior.
s

sindrenm

01/13/2022, 5:41 PM
Thanks for the issue link! You found what I could not. 👍
View count: 7