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

    Youssef Shoaib [MOD]

    03/25/2021, 8:41 PM
    In a compiler plugin, I want to generate new source files by interpreting already-existing source files (basically exactly like an annotation processor would) but while getting access to the resolved descriptors coming in from external sources (e.g. if there's a KtCallExpression to
    let
    from the stdlib, I want to get the descriptor for that call). I do realise that I can get the
    bindingContext
    and use that to call
    ktExpression.getResolvedCall
    but obviously I don't have access to that inside of a
    CollectAdditionalSourcesExtension
    so what can I do here? I'm thinking maybe I can run analysis twice or something as in run it once inside of a
    CollectAdditionalSourcresExtension
    and generate the files and then let the compiler do its own analysis normally but is that the right approach?
    r
    • 2
    • 2
  • g

    gammax

    03/26/2021, 10:58 AM
    Hey all 👋 I’m coming here as I have a question for the
    KotlinType.getJetTypeFqName
    function (here). We use this function quite a lot inside detekt when resolving types. This function is inside the JS package of the compiler:
    org.jetbrains.kotlin.js.descriptorUtils
    but it’s implementation is platform agnostic. Why is this the case? Could this be moved inside
    org.jetbrains.kotlin.descriptors
    ?
    👍 2
    b
    • 2
    • 8
  • y

    Youssef Shoaib [MOD]

    03/26/2021, 9:29 PM
    How can one parse the kotlin metadata from a
    .class
    file?
    kotlinx-metadata-jvm
    seems to give no information whatsoever about how to do this and assumes that either you're going to get it "reflectively" or "through other means". Is there an easy way to get the metadata out quickly, or would I have to go into ASM?
    e
    u
    • 3
    • 2
  • p

    pablisco

    03/30/2021, 4:46 PM
    Hopefully this is the right place to ask this 🙂 We are using the strict API for our internal modules (not published anywhere) to avoiding leaving details across modules. However, one (understandable) side effect is that any component defined as public is never marked as unused by the IDE even if there is no uses. Is there any way to make sure that we are not leaving unused code in our project? Given that we are probably not using it correctly as is 😅
    t
    t
    l
    • 4
    • 12
  • p

    pajatopmr

    03/30/2021, 9:17 PM
    It seems to me that there are three Kotlin language constructs that are of interest to a Koltin code coverage tool: 1. property initialization (top level, class and inside a function, including arguments). 2. statement and expression execution inside functions (top level, methods of a class and local functions). 3. class constructor argument initialization. (Could these be considered properties?) Surely it cannot be that simple, or can it? Granted, the second item breaks down into a number of items of interest, especially 
    if
     and 
    when
    .
    r
    • 2
    • 2
  • r

    rnett

    04/02/2021, 10:28 PM
    Are there are defined limits on IdSignature changes wrt changes in the method? I'm assuming it's tied to the ABI (i.e. if the ABI doesn't change neither will the function's signature) but wanted to check before I started depending on it.
    y
    • 2
    • 1
  • j

    Justin Tullgren

    04/06/2021, 2:14 PM
    Is there a map of original names to mangled names produced during compilation that could be used for other bytecode tools that are not part of the kotlin compilation chain? If not, does a compiler plugin get access to the original names if its run after another plugin?
    r
    • 2
    • 2
  • y

    Youssef Shoaib [MOD]

    04/06/2021, 6:44 PM
    If I need to generate files as part of a compiler plugin (i.e. in an AnalysisHandler) where should I place those generated sources? currently I'm just using the first source file I find and creating a new directory in its directory, but obviously that's extremely error-prone. I basically just want to somehow get a hold of the
    build/generated/source
    directory I guess but in a way that also works if
    kotlinc
    was called from the command-line with my plugin. I'm seriously hoping that there is a way to do this. It seems as though what
    kapt
    does for example is to just have a hard-coded value based on the gradle project.buildDir, but I'm trying to make this work in the case that gradle is for some reason not there.
    s
    j
    r
    • 4
    • 4
  • j

    Justin Tullgren

    04/07/2021, 7:49 PM
    Does anyone know what artifact has
    org.jetbrains.kotlin.name.FqName
    in it? I am getting it from
    kotlin-compiler-embeddable
    in version
    1.4.30
    but not in
    1.4.31
    This is to use the
    IrPluginContext
    builder methods.
    r
    • 2
    • 2
  • j

    Justin Tullgren

    04/08/2021, 5:17 PM
    Hi, does anyone know how to reference a Java static method in IR? I tried
    IrPluginContext#referenceFunctions(FqName)
    but the list keeps coming back empty
    y
    s
    • 3
    • 11
  • a

    Abel

    04/08/2021, 5:24 PM
    Hi, I'm trying to add a new operator to the kotlin compiler source code for academic purposes, a '**' that should be translated to '.pow' (so "2.0 ** 5.0" should be the same as "2.0.pow(5.0)"). By replicating the '*' (times) operator I'm able to add it to the lexer, and it is correctly identified and replaced, even in the kotlin bytecode viewer. Unfortunately when compiling it says "Error:(9, 17) Kotlin: 'operator' modifier is required on 'pow' in 'kotlin.math'". The issue is: the pow operation doesn't have the keyword operator, but I can't add it because otherwise I'm not able to compile it. The same also happens if I try to add a new function (let's say "public operator fun powOper(other: Int): Int" because there is no powOper in the Kotlin version I'm using to compile the source code, so I can't add the operator keyword there. What can I do?
    y
    s
    • 3
    • 8
  • j

    Justin Tullgren

    04/08/2021, 8:26 PM
    is IR fed to each plugin consecutively or is there a merge strategy involved? im wondering how the android jetpack compose plugin is successfully wrapping my IR modifications. it seems to imply my plugin went first
    y
    • 2
    • 3
  • h

    Hyugga

    04/10/2021, 10:30 PM
    I'm wanting to make a change to kotlin.flex, but when I rebuild the project I don't see any generated sources from the .flex file. There are no errors, eithers, because evidently Flex is not being use. How to I trigger this code generation in my IDEA build?
    :stackoverflow: 1
    a
    • 2
    • 4
  • s

    Strum355

    04/11/2021, 10:35 PM
    Hey, Im trying to find the closest equivalent to
    com.sun.tools.javac.code.Symbol
    from the javac compiler API. In another project Im working on, we're able to keep a mapping of Symbol to a String and be able to lookup a symbol, be it from a return type declaration, variable type etc and retrieve its String association. What would be the best option in the kotlin compiler API? Im walking the trees of KtFiles via
    KtTreeVisitorVoid
    invoked in
    analysisCompleted
    from an
    AnalysisHandlerExtension
    subclass 🙂
    y
    • 2
    • 8
  • v

    vineethraj49

    04/12/2021, 3:38 AM
    context: I'm trying replicate the behavior of https://github.com/JetBrains/intellij-community/blob/master/jvm/jvm-analysis-impl/[…]ion/blockingCallsDetection/ThrowsTypeBlockingMethodChecker.java 2 problems I'm facing: 1. @kotlin.jvm.Throws is a annotation with retention SOURCE, so how's intelliJ doing it? 2. the
    public T method() throws IllegalArgumentExpression
    ; the throws part of it is a "reference list" which seems to be in rt.jar of the JDK; how is that resolved?
    e
    • 2
    • 1
  • h

    Hyugga

    04/12/2021, 4:33 AM
    How do I adjust IDEA settings to select my modified kotlin compiler under the artifacts directory as the one I want to use going forward?
    d
    • 2
    • 2
  • l

    louiscad

    04/12/2021, 9:37 PM
    Hello, I want to compile Kotlin code to C++ code (not to machine code directly, also don't need a full-blown GC), so I can enjoy programming microcontrollers (like AVR/ATMega on Arduinos) without writing awful code. What paths do you suggest to approach such a project? Interested in seeing different approaches. Parsing Kotlin code myself (using Kotlin code of course) is an option, though I'm wondering if there's any better ways, including using backend IR 🤔.
    y
    s
    +3
    • 6
    • 23
  • j

    Jan Skrasek

    04/15/2021, 2:47 PM
    In Kotlin 1.5-RC I am unable to cast 
    Class<*>
     to 
    Class<Enum<*>>
      and use if in Java function requiring 
    public static <T extends Enum<T>> EnumJsonAdapter<T> create(Class<T> enumType) {
    Should I do it somehow differently, or is it a bug?
    d
    v
    +2
    • 5
    • 16
  • a

    aleksey.tomin

    04/16/2021, 4:11 PM
    I try to migrate kotlin-android project from 1.3.72 to 1.4.32
    plugins {
        id("com.android.application")
        id("kotlin-android")
        id("kotlin-android-extensions")
        id("com.google.firebase.crashlytics")
        kotlin("kapt")
    }
    When I build it
    ./gradlew --info assembleDebug
    I have an error (was attached in thread). How can I fix it? I haven’t found the bug in youtrack
    • 1
    • 2
  • a

    Ahmed Mourad

    04/18/2021, 3:26 AM
    Hi, can someone point out the problem with this function?
    fun KtClassOrObject.findSuperType(
        bindingContext: BindingContext,
        fqName: FqName
    ): KtSuperTypeListEntry? {
        return this.superTypeListEntries.firstOrNull { entry ->
            bindingContext.get(
                BindingContext.TYPE,
                entry.typeReference
            )?.constructor?.declarationDescriptor?.fqNameSafe == fqName
        }
    }
    It's called inside an AnalysisHandler's
    analysisCompleted
    . The problem is that
    bindingContext#get
    always returns null, despite
    entry.typeReference
    not being null, but why?
    r
    • 2
    • 5
  • s

    Strum355

    04/18/2021, 10:26 PM
    Does someone have an idea why Im getting the shown error when passing plugin options via gradle
    freeCompilerArgs
    but when manually calling
    kotlinc
    with the args, it works fine and the value is properly set?
    z
    s
    • 3
    • 4
  • m

    mikehearn

    04/20/2021, 11:03 AM
    Does anyone have experience of debugging why incremental compilation decided to rebuild a particular file? I don't have a problem, it's working, but it's recompiling and writing new classes that don't seem to have actually changed and I'm curious why.
    b
    a
    • 3
    • 3
  • j

    Justin Tullgren

    04/26/2021, 6:23 PM
    Does anyone know how i can reference a
    IrFunctionAccessExpression
    value parameter for use in another expression? I keep being told I am creating the const or getter twice when i am modifying a function body
    s
    r
    • 3
    • 11
  • b

    basher

    04/27/2021, 2:16 AM
    I’m able to crash K/N linkReleaseFrameworkIosX64 and linkDebugTestMingwX64. I’ve tried adding -Xverbose-phases=ALL to determine where it crashes, but then that caused it to run out of memory. Any other useful flags I should try?
    • 1
    • 1
  • l

    Luoqiaoyou

    04/28/2021, 12:57 PM
    Sorry to bother you, recently I was studying the kotlin compiler, I cloned the code and ran
    ./gradlew runIde
    to check my changes, but I don’t know how to debug the breakpoint directly, could anyone please help me solve it
    s
    d
    • 3
    • 4
  • a

    andi

    04/28/2021, 1:43 PM
    Hey 👋 , what are the tests I should run if I want to verify that I didn't break anything with a fix for the irToJs part of the compiler?
    s
    d
    • 3
    • 11
  • a

    andi

    04/30/2021, 2:07 PM
    I'm currently looking at KT-39891 . As mentioned in the ticket the problem could be solved by adding
    toString()
    calls for the different
    expression.arguments
    (here). The "pre IR" translator had a similar mechanism. However I'm unsure why the pre IR code also added
    toString
    for the other types (Any, Comparable, Number)? At least if I look at the kotlin.js , I can only see
    Long
    and
    BoxedChar
    implementing
    valueOf
    .
    b
    u
    • 3
    • 9
  • t

    turansky

    05/06/2021, 2:56 PM
    Is it possible to create “sugar” for serialization plugin? My visitor must be called before serialization visitor in that case. Is it possible?
    👀 1
    y
    • 2
    • 2
  • m

    Miquel Àngel Román

    05/06/2021, 9:55 PM
    Hi everyone! I found this repository on Kotlin https://github.com/Kotlin/grammar-tools and I have tried to use it; but the properties of the tree and subtrees are private and last build of the tool was produced by April 2019. How does one go about getting it updated? I have also tried to build it myself but there's a dependency missing so I can't build it. There are issues created in the repo but seems there isnt so much activity
    m
    • 2
    • 8
  • j

    Jan Skrasek

    05/07/2021, 1:34 PM
    internal interface I {}
    public class Exported {
        protected val: I? = null
    }
    Why I cannot have protected property with internal type in FINAL class?
    'protected (in Exported)' property exposes its 'internal' type I
    The usecase is a public Fragment/Activity with internal ViewModel. We have this viewmodel property abstract in the fragment's parent -> therefore protected.
    e
    r
    • 3
    • 6
Powered by Linen
Title
j

Jan Skrasek

05/07/2021, 1:34 PM
internal interface I {}
public class Exported {
    protected val: I? = null
}
Why I cannot have protected property with internal type in FINAL class?
'protected (in Exported)' property exposes its 'internal' type I
The usecase is a public Fragment/Activity with internal ViewModel. We have this viewmodel property abstract in the fragment's parent -> therefore protected.
e

Endre Deak

05/07/2021, 4:31 PM
correct me if I’m wrong but if the class is final it means that no classes can inherit from it, which makes protected (visible to itself and children) essentially useless
j

Jan Skrasek

05/07/2021, 5:06 PM
as described, abstract protected in parent is quite useful.
e

Endre Deak

05/07/2021, 5:08 PM
ah wait. The problem is different. The issue is that
interface I
is internal. But if
Exported
is public (and not final), it means that anyone could inherit, which - as the message suggests - leads to expose something internal to the public.
j

Jan Skrasek

05/07/2021, 5:50 PM
that's not the issue. the abstract type is obviously public. the implementation will be properly impl detail.
r

Roukanken

05/07/2021, 7:12 PM
I still have no idea what exactly are you trying to do? But, if I understand correctly, you want to have abstract type, with protected internal property that the public final classes will use The problem I see there though, is that public class can't extend internal one either, so the abstract would have to be public too - that means, anyone can extend it, but! - abstract internal type is visible (which it can't obviously)...
j

Jan Skrasek

05/10/2021, 10:56 AM
public interface ViewModel {
    public fun doSomething()
}

public abstract class BaseActivity {
    protected abstract val viewModel: ViewModel
}

internal class FinalViewModel : ViewModel {
    override fun doSomething() {}
    fun doSomethingElse() {}
}

public class FinalActivity : BaseActivity() {
    protected override val viewModel: FinalViewModel = FinalViewModel()
}
View count: 4