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

    majindong

    10/22/2022, 7:45 AM
    how to add parameters to a class constructor? I want to add parameters to a primary constructor in SyntheticResolveExtension, but it failed the code is: in SyntheticResolveExtension: override fun generateSyntheticClasses( thisDescriptor: ClassDescriptor, name: Name, ctx: LazyClassContext, declarationProvider: ClassMemberDeclarationProvider, result: MutableSet<ClassDescriptor> ) { if (!thisDescriptor.annotatedAsDeepCopiableDataClass()) { return } if(name.identifier=="sub") { result += trackableSubClass(thisDescriptor); } } private fun trackableSubClass( thisDescriptor: ClassDescriptor ): ClassDescriptorImpl = object : ClassDescriptorImpl( thisDescriptor, Name.identifier(SUBCLASS_NAME), Modality.FINAL, ClassKind.CLASS, emptyList<KotlinType>(), thisDescriptor.source, false, LockBasedStorageManager.NO_LOCKS ) { override fun getUnsubstitutedMemberScope(): MemberScope { return MemberScope.Empty } }.apply { val a = ClassConstructorDescriptorImpl.create( this, Annotations.EMPTY, true, this.source ) val b = ValueParameterDescriptorImpl( containingDeclaration = a, original = null, index = 0, annotations = Annotations.EMPTY, name = Name.identifier("d"), outType = thisDescriptor.builtIns.longType, declaresDefaultValue = true, isCrossinline = false, isNoinline = false, varargElementType = null, source = a.source, ) a.initialize( listOf(b), DescriptorVisibilities.PUBLIC, ) a.returnType = this.defaultType this.initialize( MemberScope.Empty, setOf(a), a ) } in IrElementTransformerVoidWithContext: fun IrClass.createSub(pluginContext: IrPluginContext){ val constructorOfAny = pluginContext.irBuiltIns.anyClass.owner.constructors.first() primaryConstructor!!.body=factory.createBlockBody( startOffset, endOffset, listOf( IrDelegatingConstructorCallImpl( startOffset, endOffset, pluginContext.irBuiltIns.unitType, constructorOfAny.symbol, 0, constructorOfAny.valueParameters.size ).apply { primaryConstructor!!.valueParameters.forEachIndexed { idx, parameter -> println(idx) println(parameter) putValueArgument(idx, IrGetValueImpl(startOffset, endOffset, parameter.type, parameter.symbol)) } }, IrInstanceInitializerCallImpl(startOffset, endOffset, symbol, pluginContext.irBuiltIns.unitType) ) ) } the error is : e: java.lang.AssertionError: org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl@2169d6d4: No such value argument slot: 0 at org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression.putValueArgument( )
  • r

    Rob Elliot

    10/22/2022, 10:38 AM
    Mildly irritating:
    try {
      TODO()
    } catch (e: Exception) {
      if (e.cause is AuthenticationException) {
        throw e.cause // does not compile!
      }
      throw e
    }
    Gives me compiler error
    Smart cast to 'AuthenticationException' is impossible, because 'e.cause' is a property that has open or custom getter
    . But all I'm doing with it is throwing it, and the only requirement of
    throw
    is that it's a
    Throwable
    - which it definitely is.
    f
    e
    • 3
    • 19
  • n

    natario1

    10/24/2022, 12:17 PM
    I see that implementing
    equals
    for value classes is not allowed. Which kind of makes sense, but what about arrays? I have a
    value class Ints(val array: IntArray)
    which fails on equality checks, because it won’t use contentEquals. Is this going to change in the future?
    s
    u
    • 3
    • 4
  • s

    Stefan

    10/24/2022, 2:47 PM
    hi, how do I specify the KType
    java.util.UUID!
    , not
    java.util.UUID
    nor
    java.util.UUID?
    ? e.g. in
    register<UUID?>(Arb.uuid())
    s
    u
    • 3
    • 2
  • h

    hfhbd

    10/25/2022, 12:08 PM
    The Kotlin compiler uses PSI classes too, don’t it? So how does the Kotlin compiler create the psi classes? Do you really run a headless IntelliJ instance? The custom language plugin tutorial and its parsers heavily based on virtual files and IntelliJ project service 🤔
    s
    • 2
    • 4
  • q

    Quantum64

    10/28/2022, 10:04 PM
    Is there any example of a working K2 plugin that builds outside of the Kotlin repo? I see all the ones inside the Kotlin repo use the "jps-compatible" plugin, but I am not sure what that is or how that works.
    z
    d
    • 3
    • 8
  • a

    Ayfri

    11/01/2022, 11:29 PM
    Is it possible to disable a specific warning as a compiler argument ? Like I want to disable the
    unused
    warning specifically for multiple gradle projects using my main
    build.gradle.kts
    or a gradle plugin included in all the plugins to avoid having the warning everywhere.
    e
    • 2
    • 2
  • s

    Slackbot

    11/02/2022, 10:57 AM
    This message was deleted.
  • y

    Youssef Shoaib [MOD]

    11/06/2022, 3:28 PM
    Any FIR way to find all library methods that have a specific annotation?
    FirPredicateBasedProvider
    seems to only work for the files being compiled. Is there a simple way to loop over all imported library methods and filter them manually? Or would that be too costly? I can see how to find the FQNs for imported packages and methods, but then I'm not sure how to loop over their "visible" methods. I'm doing this for caching reasons, so if I accidentally get methods that aren't visible, that's still fine. In other words, I'm looking for the FIR equivalent of
    module.getPackage(fqName).memberScope.getContributedDescriptors()
    d
    • 2
    • 11
  • p

    PHondogo

    11/08/2022, 2:28 PM
    Hello!
    class A<T>(
      val klass: KClass<T> // compilation error if T is not T : Any. But I can't make it T : Any, cause see test function declaration below
    ) {
    
      fun test(a: T) {
        if (a == null) {
          println("Value is null")
        } else {
          // use a::class 
        }	
      }
    
    }
    How to tell compiler that KClass must use T!! while in function test T's nullable must depends on actual T's nullability?
    d
    • 2
    • 3
  • s

    SASANQUA

    11/10/2022, 2:33 AM
    Hi! I am trying to set up a standalone environment to play around with building a language server. I am new to the compiler internals, and I know that
    KotlinCoreProjectEnvironment#project
    can be used to obtain services (
    PsiManager
    ,
    PsiFileFactory
    ...). But I am wondering whether the
    KotlinCoreProjectEnvironment
    is a one-time use only so that when any files in a root directory change, the whole environment needs to be recreated. I can obtain a
    PsiFile
    instance through
    PsiManager
    but I cannot call
    PsiManager#reloadFromDisk
    when a file change because that throws
    Missing extension point: com.intellij.psi.treeChangePreprocessor in container com.intellij.mock.MockProject@4a8355dd
    .Am I doing this wrong or are there other ways to do it? It also seems that I can only add a root (as a directory or a jar) through
    JavaCoreProjectEnvironment#addSourcesToClassPath
    or
    JavaCoreProjectEnvironment#addJarToClassPath
    but cannot remove them. I tried looking into
    intellij-community
    and it seems to use a
    ProjectExImpl
    instance but not sure where it registers all its services or how it manages text changes in a file. Any help would be appreciated!
  • e

    eygraber

    11/10/2022, 6:08 PM
    Are there any updates as to when a stable compiler plugin API is going to be ready? Last I heard it was unofficially 1.8 or 1.9, but also possible later 😅
    d
    • 2
    • 4
  • r

    raulraja

    11/11/2022, 4:07 PM
    Hi I'm trying to access the classes and types at https://github.com/JetBrains/kotlin/blob/ddc72db0de5a707ffafa2fac15a1b887ed903800/[…]tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator but I can't find an artifact where those are published. Is there an artifact published for the FIR / IR Tree Generators the compiler uses to generate the source files for those models? thanks!
  • z

    Zac Sweers

    11/11/2022, 6:01 PM
    Would it be possible to make this warning configurable when using
    "-Xuse-fast-jar-file-system"
    ?
    w: Using new faster version of JAR FS: it should make your build faster, but the new implementation is experimental
    We’d like to take through its paces in our repo and test it out, but we also can’t afford to disable
    -Werror
    . Can file a report on YouTrack too if that’s easier edit: went ahead and filed https://youtrack.jetbrains.com/issue/KT-54928
  • s

    server

    11/12/2022, 9:53 AM
    is it possible to get method parameters named from method invocation? example: org.jetbrains.kotlin.psi.KtDotQualifiedExpression = DOT_QUALIFIED_EXPRESSION [SomeClass().someMethod( 1, 2, "aaa" )] I like to know all names of the argument of someMethod
  • r

    Rob Elliot

    11/15/2022, 1:09 PM
    I think there was some discussion of this earlier - is there any proposal to make anonymous objects have an associated type capturing their members?
    h
    e
    +3
    • 6
    • 17
  • p

    Paul Samuels

    11/17/2022, 11:14 AM
    @Dariusz Kuc I think I’m hitting this - did you manage to find any workaround at all?
  • l

    Leon Linhart

    11/17/2022, 2:56 PM
    Hi! Is there a FIR equivalent to the
    DiagnosticSuppressor
    ? I'm currently prototyping a plugin which slightly tweaks the behavior of a few checks by reimplementing them and suppressing the relevant diagnostics reported by the default ones. This seems to be feasible in K1 but I didn't find a way to suppress diagnostics in such a case using FIR yet.
    d
    • 2
    • 3
  • s

    Sam Gammon

    11/18/2022, 2:07 AM
    hello compiler friends. i am thinking of a compiler plugin that i would like to build but i wanted to ask a few questions first, to determine whether it is possible within the current architecture. is this the right place?
    • 1
    • 1
  • p

    PHondogo

    11/18/2022, 3:17 PM
    Just wonder why need both fir and ir? Why not to have only one single middle ir?
    t
    • 2
    • 1
  • t

    Tóth István Zoltán

    11/21/2022, 6:22 AM
    Are there any plans to address the slow hot-reload for JS. I've seen that incremental compilation will be default for 1.8.0 but I remember reading that it's not a big improvement. It is is a real productivity problem for us to wait for the browser to refresh the page. I am willing to put some effort into this if there are no current plans. Ideas: • replace webpack with es • make webpack optional, use modules directly without DCE and minimization (for development) • implement a proper multi-module approach Your opinion about this is most welcome. The JS community would welcome faster development very much and it would open new possibilities for Kotlin.
    c
    • 2
    • 7
  • j

    Johannes Barop

    11/21/2022, 12:32 PM
    Hi, i am writing a compiler plugin. I have difficulties calling a method on an object (property of a class). For example, with static methods I do it with `pluginContext.referenceFunctions(FqName("kotlin.io.println")); irCall(funPrintln) ...``. Can anyone give me a tip on how this works with functions on an instance? Thanks!
    s
    r
    n
    • 4
    • 9
  • s

    Sam Gammon

    11/22/2022, 3:09 AM
    hello kotlin compiler experts, i have a question about how to debug the invocation of a compiler plugin. i know about
    org.gradle.debug=true
    and
    in-process
    mode for the Kotlin compiler, but it still doesn't hit my breakpoints within the plugin. the plugin is in a composite build, and i am running the compile from the parent build -- my hope is to apply the plugin within the parent build. so far, i'm able to confirm that the following is working correctly: • the gradle sub-plugin which hosts the compiler plugin is applied (i hit a breakpoint here) • the gradle sub-plugin correctly states that it
    isApplicable
    • the plugin JAR ends up on the command line at
    -Xplugin=
    • the plugin args end up on the command line at
    [..., -P, ":plugin:<name>:enabled=true,..."]
    despite all of this: • a test that verifies the plugin's effects fails • i cannot hit breakpoints within the compiler plugin, but i can within the gradle script • i do not see log messages reported via
    <http://CompilerMessageSeverity.INFO|CompilerMessageSeverity.INFO>
    • i do not see log messages reported via
    CompilerMessageSeverity.LOGGING
    • but then again maybe the plugin isn't running, or isn't hitting that code? has anybody seen this before? thank you in advance for any help
  • s

    Sam Gammon

    11/22/2022, 4:35 AM
    hey all -- nevermind, i solved it 🙂 was missing a service file for
    org.jetbrains...ComponentRegistrar
    y
    • 2
    • 2
  • j

    jessewilson

    11/22/2022, 10:01 PM
    I found a small (but devastating!) bug in Kotlin/Native. In places, .klib files omit symbols generated with IR and that can cause a crash when deserializing 'em:
    18:28:11 e: java.lang.IllegalStateException: Expecting descriptor for app.cash.zipline.internal.bridge/SuspendCallback.Companion.Adapter|null[0]
    18:28:11 	at org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker$KonanCachedLibraryModuleDeserializer.tryDeserializeIrSymbol(KonanIrlinker.kt:644)
    18:28:11 	at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer.deserializeIrSymbol(BasicIrModuleDeserializer.kt:111)
    My read of the problem is the .klib descriptor only includes from the PSI model. So if I’m synthesizing new ones with IR, they’re not in the descriptor. Further details on my tracking bug.
    p
    • 2
    • 7
  • m

    mzgreen

    11/24/2022, 6:32 PM
    Hey folks! I've looked at the channel list and couldn't find a compiler plugin specific one so if this isn't the right channel then forgive me and point me to the right one please :) I'm starting learning about compiler plugins. I've read a bunch of posts and now I'd like to do something in practice. I have a couple of questions: 1. If I want to make my plugin work with all Kotlin targets then which APIs should I avoid? For example can I use Psi for inspection? 2. Is it possible to configure the plugin so that it's executed after or before some specific Kotlin compiler transform? For example I'd like to run my plugin before or after Kotlin compiler processes data classes. Is this possible? 3. Does Kotlin Ir contain info about line numbers? I was able to get that info using Psi and DocumentManager but I'm not sure if this is the best way to do it and if it'll work only on JVM or on all targets.
  • p

    Piotr Krzemiński

    11/25/2022, 1:03 PM
    I'm looking for resources on writing compiler plugins. So far I found: •

    https://youtu.be/w-GMlaziIyo▾

    • https://bnorm.medium.com/writing-your-second-kotlin-compiler-plugin-part-1-project-setup-7b05c7d93f6c but I'm aware that the API moves fast. Is there some fresh tutorial or example plugin? I've been looking around source code of existing plugins, but first I want to check if there are some guides.
    b
    j
    • 3
    • 31
  • p

    Piotr Krzemiński

    11/25/2022, 4:21 PM
    I'd like to better understand what FIR plugins are. I understand they're related to IDE support and that FIR stands for Frontend IR (right?). But why aren't just backend IR plugins enough for the IDE? Do compiler plugins always come in pairs (backend and frontend), like socks? And finally, is FIR plugin needed if I plan to work only with backend IR? What would the plugin do in such case? CC @Big Chungus
    h
    j
    +2
    • 5
    • 18
  • p

    pablisco

    11/27/2022, 6:58 PM
    This may have been asked before, sorry if it has 🙈 I was wondering if someone has managed to compile or interpret Kotlin code from Kotlin itself. I haven’t found anything that could work on a KMP project.
    j
    e
    • 3
    • 3
  • s

    server

    11/27/2022, 8:13 PM
    is there any cool way to validate string length in method call without writing compiler plugin? maybe arrow meta can do this? string here is one first argument of a method
    j
    a
    • 3
    • 2
Powered by Linen
Title
s

server

11/27/2022, 8:13 PM
is there any cool way to validate string length in method call without writing compiler plugin? maybe arrow meta can do this? string here is one first argument of a method
j

Javier

11/27/2022, 8:14 PM
Maybe Arrow Analysis can help you
a

Alejandro Serrano Mena

11/28/2022, 8:17 AM
yes, this is one of the functionalities you can get using Arrow Analysis (which is itself a compiler plug-in, but you don’t have to write it 😉 )
View count: 8