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

    Marc Knaup

    01/15/2022, 3:06 PM
    Is there any ETA on the K2 compiler? I can’t believe that I have a brand new MacBook Pro and my entire OS still becomes partially unresponsive while Kotlin is compiling something or while the IDE is doing whatever 😅
    d
    c
    +4
    • 7
    • 15
  • s

    server

    01/17/2022, 1:11 PM
    I now work on plugin and I have to work with KtClass(and similar classes). I really don't like it. Is there any way to convert KtClass to PsiClass (like in intellij plugins)?
    d
    • 2
    • 14
  • p

    Piotr Krzemiński

    01/20/2022, 9:58 AM
    Sad development of events in case of the issue of incorrect line numbering in stack traces: [KT-8628] Line numbers are incorrect in exception stack trace . JDK folks resolved the JDK issue (which was first rebranded as an enhancement request) as wontfix, which doesn't give hopes to fix the issue that Kotlin users face. Any idea what to go from here? I'd personally challenge the fact that it's not a bug in JDK. I don't have proper expertise within the JDK/JVM internals so cannot push the discussion forward. Once it's proven to be a bug, there's a chance to get it back on track.
    👀 1
    c
    • 2
    • 4
  • r

    Rescribet

    01/20/2022, 10:56 AM
    Is/will there (be) a way to build Kotlin applications programatically? The use-case is an application which holds a representation of a user-defined set of models, and using the Kotlin compiler to do first line validations (field collisions, inheritance, etc) and typescript interface generation.
    • 1
    • 1
  • h

    hfhbd

    01/24/2022, 4:39 PM
    Is there any way to enable more logs when the IR validation fails?
    java.lang.IllegalStateException: Validation failed in file main.kt
    is almost impossible to debug without any hints. And the stack trace is not very helpful.
    👍 1
    • 1
    • 1
  • m

    Matt Robertson

    01/27/2022, 10:11 PM
    What is the name of the syntactical feature where you can scope a
    Unit
    to be a sort of anonymous extension function on a given class? I noticed it in the Compose code (I think) but I haven't been able to find it in the docs. Example:
    fun render(node: Node, action: Node.() -> Unit) {
        node.action()
    }
    e
    • 2
    • 9
  • r

    rrva

    01/30/2022, 4:29 PM
    I want to modularize a codebase further to improve build times. A fun idea I had was to make module boundaries such that most historical commits only touch one module. What is a good way to algorithmically create such a grouping of files into modules?
    k
    • 2
    • 3
  • c

    Chachako

    01/31/2022, 4:34 PM
    Hello everyone, I have a question about compiler plugin, can I delay
    SyntheticResolveExtension
    execution? I need to synthesize a new property, and then the type of this property depends on the initializer expression of another property, so I must use
    BindingContext.getType
    to parse the actual type of another property’s initializer, but unfortunately
    SyntheticResolveExtension
    is executed a bit too early, at this time the value returned by the
    BindingContext.getType
    is
    null
    . Or is there another way for me to infer the type of another expression during synthesis?
    d
    • 2
    • 20
  • c

    Chachako

    01/31/2022, 5:06 PM
    Another question is how to get all the declared descriptors in the
    ClassDescriptor
    ? I found this usage: https://github.com/JetBrains/kotlin/blob/1.6.0/plugins/kotlin-serialization/kotlin[…]otlinx/serialization/compiler/resolve/SerializableProperties.kt, but I can’t use it, an error will be thrown when I try to use the same code:
    e: java.lang.AssertionError: Recursion detected on input: actualType under LockBasedStorageManager@30057fbe (TopDownAnalyzer for JVM)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.getContributedVariables(AbstractLazyMemberScope.kt:139)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getContributedVariables(LazyClassMemberScope.kt:395)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.computeDescriptorsFromDeclaredElements(AbstractLazyMemberScope.kt:234)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.doDescriptors(LazyClassMemberScope.kt:68)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.access$doDescriptors(LazyClassMemberScope.kt:52)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope$allDescriptors$1.invoke(LazyClassMemberScope.kt:64)
    d
    • 2
    • 3
  • c

    Chachako

    02/03/2022, 5:54 PM
    I wonder if the frontend of compiler plugin has extension that implicitly modify visibility of declarations. I want to make the constructors of all classes marked with an annotation
    private
    . Is that possible now?
    d
    r
    • 3
    • 8
  • l

    Lewis Jacobs

    02/07/2022, 4:06 PM
    Hello everyone! 👋 I have a situation where I need to compile a fairly large Kotlin application (that I don't want to rewrite into Java!) so it can run on target version Java 1.5. I'm reading in the docs here https://kotlinlang.org/docs/compiler-reference.html#jvm-target-version that the lowest supported version (which is deprecated) is 1.6. Is it completely impossible to achieve bytecode that can run on a VM that's version 1.5? Otherwise, any ideas on how to progress without re-writing the whole thing in Java 1.5? 😬 Thank you! 🙏
    p
    • 2
    • 3
  • s

    server

    02/07/2022, 7:12 PM
    I get
    * What went wrong:
    Execution failed for task ':generateMavenPluginDescriptor'.
    > org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException: No mojo definitions were found for plugin: com.bnorm.template:kotlin-ir-plugin-template.
    j
    i
    • 3
    • 4
  • s

    server

    02/07/2022, 7:25 PM
    is it possible to somehow convert project to maven?
    i
    • 2
    • 3
  • s

    server

    02/08/2022, 11:19 PM
    maybe I need to add some more jars as dependencies? my plugin has this
    dependencies {
        compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable")
    
        kapt("com.google.auto.service:auto-service:1.0")
        compileOnly("com.google.auto.service:auto-service-annotations:1.0")
    
        testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
        testImplementation(kotlin("test-junit"))
        testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
        testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.4")
    
        testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.1")
    s
    • 2
    • 2
  • p

    Peter Mandeljc

    02/09/2022, 9:27 AM
    if I write a class like
    class Foo { private val bar = "bar" }
    , is compiler smart enough to convert bar to static field (companion object)?
    f
    d
    • 3
    • 2
  • j

    Javier

    02/09/2022, 12:57 PM
    Is it possible to download the IDE plugin for the version
    build-1.7.0-dev-1671
    without having to build it myself?
    d
    m
    • 3
    • 15
  • m

    mikehearn

    02/10/2022, 12:37 PM
    Is there a way to change the nullability annotation the Kotlin compiler emits into class files?
    e
    • 2
    • 1
  • m

    mikehearn

    02/10/2022, 12:38 PM
    I would like to reflect over nullability at runtime, but, without using Kotlin reflection (which is very slow and anyway, reduces java interop). Unfortunately the compiler produces org.jetbrains.annotation.Nullable which isn't retained at runtime.
    w
    e
    • 3
    • 3
  • e

    eygraber

    02/10/2022, 7:00 PM
    Is there an API I can use to determine what properties/functions are unused in a given set of classes in my project (without using the IDE)?
    t
    • 2
    • 3
  • c

    Coffee Guy

    02/13/2022, 6:22 AM
    How can I make a JVM static function without using a companion object? GraalVM native image is being really funky with it and errors out.
    h
    s
    g
    • 4
    • 5
  • s

    Shreyas Patil

    02/14/2022, 1:32 PM
    I know the reason due to which I'm able to write this without any issues. But should I be able to do that with strict type checking?
    e
    p
    • 3
    • 2
  • r

    rocketraman

    02/17/2022, 4:51 PM
    It used to be that Java interfaces with default implementations were called instead of a delegate -- I thought this was fixed in 1.4? I'm on a project using 1.5.31 and am still seeing that behavior, while my jvm target is 11. Why would that be?
    u
    • 2
    • 2
  • m

    mbonnin

    02/18/2022, 3:27 PM
    Are there documented limits about what the compiler can accept? I have a 357k lines file containing a class with a ton of nested classes and any code referencing it fails to compile with
    Unresolved Reference
    . I'm not really expecting this use case to work but curious when to giveup and throw a better error message than
    Unresolved Reference
    h
    e
    • 3
    • 4
  • m

    myotive

    03/01/2022, 11:52 PM
    Hello! 👋 (cross posting this from #ksp) Is this a good place to discuss Kotlin Compiler Plugin’s? I’m trying to write a plugin that will add Gson’s
    @SerializedName
    annotation and Moshi’s
    @Json
    annotation to all the properties of a data class. Everything seems to be working in my transformer (
    IrElementTransformerVoidWithContext
    ) , but the resulting class doesn’t seem to have the annotations when I try to run a unit test (which loads the class from a temp working directory). If anyone has any documentation or resources that could help, I would be most grateful. Thanks!
    ➕ 1
    r
    • 2
    • 21
  • v

    ventura

    03/02/2022, 11:39 AM
    [thread] Kotlin IR Documentation (Stack Code & Tuples)
    p
    j
    m
    • 4
    • 25
  • m

    Michael

    03/02/2022, 2:04 PM
    Are there any regressions in 1.6.20-RC? Trying to use 1.6.20-RC fails to build my existing 1.6.10 code with the following error
    java.lang.AssertionError: SyntheticAccessorLowering should not attempt to modify other files!
    https://pastes.dev/IumlkSq7Qg
    d
    • 2
    • 1
  • g

    galex

    03/04/2022, 6:40 AM
    Is there a listing of all the frontend and backend compiler extensions somewhere?
    d
    • 2
    • 2
  • n

    Nick

    03/08/2022, 3:36 AM
    Is @JvmName supposed to allow characters from this list to work within identifiers when with back ticks? Kotlin/JVM (any declaration publicity) ~ ( [\r\n] | '`' | '.' | ';' | ':' | '\' | '/' | '[' | ']' | '<' | '>' ) https://kotlinlang.org/docs/reference/grammar.html#Identifier
    b
    y
    • 3
    • 12
  • d

    Dariusz Kuc

    03/10/2022, 2:22 AM
    Hello 👋 Was just wondering - are there any plans with the new compiler to generate some default value metadata so it could be accessed through a reflection? Guessing no as that is pretty fringe use case.
    u
    • 2
    • 2
  • m

    Matthias Geisler

    03/15/2022, 7:53 AM
    Hello lovely people - I have one small question - does anybody knows if the order of plugins is arbitrary or does the compiler sticks to the order in which the plugins are registrated?
    r
    y
    • 3
    • 3
Powered by Linen
Title
m

Matthias Geisler

03/15/2022, 7:53 AM
Hello lovely people - I have one small question - does anybody knows if the order of plugins is arbitrary or does the compiler sticks to the order in which the plugins are registrated?
r

raulraja

03/15/2022, 9:03 AM
Hi @Matthias Geisler, My experience is that the compiler preserves order of registration when invoking the registered extensions. Something to keep in mind is your plugin still will get invoked after other plugins if they are registered for different phases regardless of order of registration. For example:
Plugin1 -> Alters IR backend
Plugin2 -> Operates on Analysis
Plugin2 gets call first because Plugin1 refers to a later phase since IR comes after Analysis.
Plugin1 -> Operates on Analysis
Plugin2 -> Operates on Analysis
Plugin1 gets call first because refers to the same phase but was registered first.
y

Youssef Shoaib [MOD]

03/15/2022, 9:03 AM
It's in order of registration. However, you can force your own order like Anvil does:
private fun AnalysisHandlerExtension.Companion.registerExtensionFirst(
    project: MockProject,
    extension: AnalysisHandlerExtension
  ) {
    project.extensionArea
      .getExtensionPoint(AnalysisHandlerExtension.extensionPointName)
      .registerExtension(extension, LoadingOrder.FIRST, project)
  }
m

Matthias Geisler

03/15/2022, 9:07 AM
Awesome that helps a lot! Thx!
View count: 2