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

    Manuel Dossinger

    07/08/2022, 10:17 AM
    hi. When I got a compiler exception (not just an error message), is this the right channel to report it?
    s
    • 2
    • 1
  • m

    Michael Paus

    07/10/2022, 7:18 AM
    I have just tried to update an example multiplatform project to 1.2.0-alpha01-dev741 and Kotlin 1.7.10 (1.7.0 is the same) from dev-731 and Kotlin 1.6.21 and get the following error message when I build for iOS
    java.lang.IllegalStateException: IrBasedSimpleFunctionDescriptor: FUN name:DataTooltipArea visibility:public modality:FINAL <> (dataString:kotlin.String, modifier:androidx.compose.ui.Modifier, content:kotlin.Function2<androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit>) returnType:kotlin.Unit [expect]
    The project builds and runs perfectly on JVM and even on Web (Canvas). Can anybody tell me what this error message actually means?
    d
    k
    • 3
    • 11
  • f

    fwcd

    07/11/2022, 2:26 AM
    Is there a way to do incremental parsing/compilation of `KtFile`s in a standalone application that only uses the Kotlin compiler APIs and
    intellij-core
    , i.e. outside of an IDE context? Creating `LightVirtualFile`s and passing them to
    PsiManager.findFile
    yields an initial parse, but is there a way to e.g. update a certain text range in the virtual file and also trigger an update to the PSI? My attempts to modify the virtual file e.g. by
    setBinaryContent
    or
    setContent
    either caused the PSI file to not get updated at all or throw an exception that it's out-of-sync with the virtual file
    👀 1
  • j

    Johann Beleites

    07/13/2022, 6:52 AM
    Hey everyone. We are using the embedded compiler and just upgraded from 1.6.21 to 1.7.0. All of a sudden, we can't resolve certain types using the binding context, many (all?) of which seem to be coming from the Java standard library (e.g.
    java.util.Properties
    ,
    javax.crypto.Cipher
    ). I've been debugging a little already and found that the new version behaves differently during resolution of imports and 1.7.0 doesn't seem to successfully resolve these types anymore. I haven't been able to pinpoint the exact place where this is caused yet. Can anyone tell me if there is something to watch out for in 1.7.0? Am I missing something?
    • 1
    • 1
  • m

    Michael Paus

    07/16/2022, 8:10 AM
    Why is the Java statement
    public static final long  SIGN_BIT_MASK  = 0x8000000000000000L;
    a perfectly legal statement and its Kotlin counterpart
    const val SIGN_BIT_MASK: Long = 0x8000000000000000L
    results in an error? (Value out of range.) Such inconsistencies make it very difficult to port any Math libraries from Java to Kotlin.
    t
    • 2
    • 3
  • t

    Tóth István Zoltán

    07/16/2022, 8:12 AM
    Hi! I'm working on an IR plugin and I'm not sure how to report errors. The easiest way would be to collect the errors during the IR visits/transformations. Is this possible or do I have to use a DeclarationChecker instead? The first thing I would like to report is declaration of variables at some points of the code. I see the point in declaration checkers, only I have to write things twice if I have to work both with Kt and Ir structures.
    • 1
    • 1
  • n

    natario1

    07/16/2022, 7:51 PM
    Stupid question - I’m trying to write a hello world compiler plugin and apparently it is not being invoked. How would you go to debug this situation? I can see that the provider lambda returned by
    KotlinCompilerPluginSupportPlugin.applyToCompilation
    is invoked, so kotlin is preparing the args to be passed to the plugin. There I have a command line processor and an IrGenerationExtension. I’m adding all kinds of logs - println(), error(“Hello world”), send stuff to createDiagnosticReporter(). But I get nothing, compilation succeeds. Not sure what to do, maybe there is some compiler flag that can give me more information?
    y
    • 2
    • 2
  • m

    martmists

    07/17/2022, 1:30 AM
    Why am I getting this warning when the library is built with 1.7.10 and I'm also using 1.7.10?
    y
    • 2
    • 3
  • m

    martmists

    07/17/2022, 10:11 AM
    Getting an error related to extending a method with context receivers but only in a different project with a jar dependency on the one I'm overriding, is this a known bug?
  • m

    Mikhail

    07/19/2022, 4:52 PM
    Huh? The project I use was built with java 11 target and the current project uses java 17 target
    • 1
    • 1
  • j

    Johann Beleites

    07/20/2022, 1:38 PM
    Take the following code snippet:
    abstract class Base {
        open fun foo() = "Base"
    }
    class A: Base()
    class B: Base() {
        override fun foo() = "B"
    }
    
    fun main(vararg args: String) {
        val foo: Base = B()
        if (foo is B) println(foo.foo())
    }
    The call to
    foo.foo()
    in the main method results in
    B
    to be printed, as expected. However, when I try to resolve
    foo.foo()
    using the compiler, it resolves it to the implementation in
    Base
    . This can be observed as well when pasting the code into IntelliJ and
    Ctrl + clicking
    on
    foo.foo()
    call. If I change the line to
    println((foo as B).foo())
    the static resolution works as expected and resolves to the implementation in
    B
    . I don't know how exactly smart casts work internally, however, shouldn't the compiler resolve to
    B#foo
    in both cases?
    m
    d
    • 3
    • 2
  • p

    PHondogo

    07/20/2022, 3:15 PM
    Hello! I've updated Kotlin compiler to 1.7.0 version and want to use underscore operator for template parameters type infer in such code:
    abstract class SomeClass<T> {
        abstract fun execute(): T
    }
    
    class SomeImplementation : SomeClass<String>() {
        override fun execute(): String = "Test"
    }
    
    open class Test<S: SomeClass<T>, T>
    
    class Test1 : Test<SomeImplementation, _>() //  compiler complains about  Unresolved reference: _
    d
    • 2
    • 5
  • c

    Chachako

    07/21/2022, 4:49 AM
    Will Kotlin IR include the Java source files?
    d
    y
    • 3
    • 2
  • m

    Mikhail

    07/21/2022, 7:53 PM
    Is there any way to disable mangling for functions that consume inline classes? Spring Data cant deal with this.
    e
    • 2
    • 16
  • s

    Stumpos

    07/22/2022, 8:28 PM
    If anyone is looking for an example of a plugin that does some extensive code generation https://github.com/facebookresearch/optimizer-plugins is now open source.
  • l

    louiscad

    07/23/2022, 3:17 PM
    Hello, since Kotlin 1.7.10, I consistently get this error when building a Wear OS (Android) app:
    Could not perform incremental compilation: Could not connect to Kotlin compile daemon
    Could not connect to kotlin daemon. Using fallback strategy.
    What could cause this?
  • m

    Mikhail

    07/25/2022, 3:19 AM
    Is there a way to make annotation
    @NotBlank
    appear within the type declaration on the field but not in the constructor parameter?
    • 1
    • 2
  • t

    Tóth István Zoltán

    07/26/2022, 3:54 AM
    In an IR plugin using
    dump
    , I see that the compiler generates fake overrides for everything defined in the superclass. Is this necessary for the backend? I mean it is not a trouble to generate them but it makes the generated IR quite big. What do these fake overrides actually do?
    i
    • 2
    • 2
  • y

    Youssef Shoaib [MOD]

    07/26/2022, 12:14 PM
    Is there any compile-time-evaluated way to check if a reified type is a specific class?
    T::class == Desired::class
    doesn't seem to be evaluated at compile time. I can also do
    valueOfTypeDesired is T && !(valueOfSupertypeOfDesired is T)
    but again this isn't evaluated at compile time. I'm interested not only because of performance but for a value-class optimization use case (can give more details if interested).
    t
    s
    • 3
    • 5
  • j

    jessewilson

    07/26/2022, 1:53 PM
    We’ve got a multiplatform compiler plugin in Zipline. When I upgraded from Kotlin 1.6.21 to 1.7.10 I was surprised to learn that we must use the embeddable plugin everywhere including Kotlin/Native. In particular our
    ComponentRegistrar
    now uses
    <http://org.jetbrains.kotlin.com|org.jetbrains.kotlin.com>.intellij.mock.MockProject
    on all platforms. (We had been using
    com.intellij.mock.MockProject
    for Kotlin/Native). Is this expected? It’s awesome
    s
    • 2
    • 3
  • y

    Youssef Shoaib [MOD]

    07/29/2022, 12:39 AM
    This fails with a JNI error at runtime
    context(Unit, Boolean)
    fun bothContexts() {
      // Refers to String.toInt() for some reason
      toInt()
    }
    Looks pretty bad to me. Has this been reported already? It doesn't reproduce in FIR btw.
    d
    • 2
    • 1
  • s

    Sam

    07/29/2022, 7:58 AM
    When I have a function that expects a value of type
    (A) -> B
    , it’d be cool to be able to just pass
    ::foo
    instead of
    A::foo
    . Is there a name for what I want? Even better, is there an existing ticket/proposal for it? Example:
    data class A(val name: String)
    fun <B> A.getProp(prop: (A) -> B) = prop(this)
    fun A.getName() = getProp(::name) // I want this
    fun A.getName2() = getProp(A::name) // But I have to do this instead
    c
    • 2
    • 5
  • p

    PHondogo

    07/29/2022, 10:55 AM
    Hello! What is the syntax to call super for overriden function that has additional receiver?
    open class Test {
      open fun SomeClass.test(){}
    }
    
    class Test2 : Test() {
      override fun SomeClass.test() {
        super.test() // is compilation error
      }
    }
    d
    u
    • 3
    • 3
  • n

    natario1

    07/29/2022, 4:40 PM
    I’m writing a plugin to generate
    @CName
    functions and have them exported in the final K/N binary. But looking at the file with
    nm
    , I can see that the generated symbol is not exported. Is it even possible to achieve this? Maybe the export pipeline runs before
    IrGeneration
    and so my symbol is useless? Or I’m doing something wrong. I’m generating my function and then calling
    irFile.declarations.add(function)
    , something I’m a bit unsure of.
    s
    • 2
    • 3
  • n

    natario1

    07/31/2022, 3:02 PM
    How do you reference another function (or wrap it in a lambda) in IR? I have a
    fun hello(who: String) = "Hello, $who!"
    as a
    IrSimpleFunction
    . I need to pass this to a fun
    process(function: (String) -> String)
    , but I’m confused as to how to pass my function as a value argument to another. To be clear, in source code I’d do process(::hello) or process { hello(it) }.
    s
    t
    • 3
    • 3
  • m

    Mendess

    08/01/2022, 11:07 AM
    Hey! I have never written a compiler plugin and I was wondering if I it's possible to write one that adds an annotation like this
    @MustUse
    class Foo
    and every function that returns a Foo will issue a warning at call site the returned value is not used in some way
    t
    • 2
    • 1
  • j

    Javier

    08/03/2022, 11:09 PM
    I am getting an empty list when I call
    function.contextReceivers
    where
    function
    is
    KtNamedFunction
    with Kotlin 1.7.10. Is there any way to get the list of context receivers?
    d
    • 2
    • 21
  • n

    natario1

    08/04/2022, 9:04 AM
    Does anyone know what this means?
    IllegalStateException: No file for io.company.product.sample/functionName|8889119292615326163[0] in module
    <io.company.product:sample>
    I’m trying to change value params and return type of a top level function. I’m using
    irFile.transformChildrenVoid
    and then
    function.deepCopySavingMetadata
    and then doing my changes. Compilation works, but I get the error above when linking the native binary.
    s
    • 2
    • 2
  • a

    Alexander Maryanovsky

    08/04/2022, 3:40 PM
    Today (well, yesterday actually) I realized that every lambda and function reference is compiled (for the JVM) into a separate class, and this slows down app startup.
    h
    z
    m
    • 4
    • 7
  • r

    reactormonk

    08/04/2022, 3:49 PM
    I've got two sealed classes
    CurrentState
    and
    DesiredState
    . When doing
    val x = when (CurrentState to DesiredState) { ... }
    , the exhaustiveness checker doesn't seem to like the non-existence of an
    else
    , even if I covered all branches. Any way to help it out a bit?
    d
    • 2
    • 13
Powered by Linen
Title
r

reactormonk

08/04/2022, 3:49 PM
I've got two sealed classes
CurrentState
and
DesiredState
. When doing
val x = when (CurrentState to DesiredState) { ... }
, the exhaustiveness checker doesn't seem to like the non-existence of an
else
, even if I covered all branches. Any way to help it out a bit?
d

dmitriy.novozhilov

08/04/2022, 6:23 PM
Exhautive checker does not work this way, because Pair of to sealed classes is not exhaustive class BTW how do you check for pair components are is instance of some inheritor?
r

reactormonk

08/05/2022, 7:54 AM
Is there a way to make an exhaustive check for a product of sealed classes?
d

dmitriy.novozhilov

08/05/2022, 7:57 AM
sealed class A
class B : A()
class C : A()

sealed class X
class Y : X()
class Z : X()

fun test(a: A, x: X) {
    val result = when (a) {
        is B -> when (x) {
            is Y -> 1
            is Z -> 2
        }
        is C -> when (x) {
            is Y -> 3
            is Z -> 4
        }
    }
}
r

reactormonk

08/05/2022, 7:57 AM
Can't push it into a single
when
statement?
d

dmitriy.novozhilov

08/05/2022, 7:57 AM
No
r

reactormonk

08/05/2022, 1:39 PM
Should the exhaustiveness check also work with
sealed class DesiredState: Parcelable {
    @Parcelize
    object MainPage: DesiredState()
    @Parcelize
    object AcceptCall: DesiredState()
}
?
Currently tells me I also need an
else
branch
d

dmitriy.novozhilov

08/05/2022, 1:47 PM
sealed class DesiredState: Parcelable {
    @Parcelize
    object MainPage: DesiredState()
    @Parcelize
    object AcceptCall: DesiredState()
}

fun test(state: DesiredState) = when (state) {
    is DesiredState.MainPage -> "OK"
    is DesiredState.AcceptCall -> "Error"
}
Works fine
r

reactormonk

08/05/2022, 1:53 PM
Looks like intellij got stuck somewhere, works fine.
I've got a weird case here where Intellij tells me I need an
else
branch, but the compiler is fine with it 🤔
d

dmitriy.novozhilov

08/08/2022, 8:09 AM
Please report issue about it to YT
r

reactormonk

08/08/2022, 9:39 AM
Probably https://youtrack.jetbrains.com/issue/KTIJ-19528/IDE-Scripts-false-positive-NOELSEINWHEN-for-sealed-hierarchy
d

dmitriy.novozhilov

08/08/2022, 9:56 AM
Looks similar
View count: 8