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

    PHondogo

    09/12/2022, 8:05 PM
    Hello! Please advice me what IrExpression to use to put lambda as value parameter to function. I tried IrFunctionExpressionImpl but got Unexpected IR element found during code generation.
    s
    n
    2 replies · 3 participants
  • p

    Philip Graf

    09/13/2022, 7:37 AM
    Hi all, I'm trying to get the compiler to compile a data class so that I have annotations on the getter's return type and return type parameter in the generated bytecode, e.g. something like
    data class Pet(val names: @get:NonNull List<@get:NonNull String>)
    to compile to
    public getNames()Ljava/util/List;
      @Lorg/eclipse/microprofile/graphql/NonNull;() : METHOD_RETURN, null
      @Lorg/eclipse/microprofile/graphql/NonNull;() : METHOD_RETURN, 0;
    However, if I compile the data class above, I get two compile errors for each annotation: - This annotation is not applicable to target 'undefined target' and use site target '@get' - This annotation is not applicable to target 'type usage' and use site target '@get' The NonNull annotation is from the Java library microprofile-graphql-api:
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
    @Documented
    public @interface NonNull {
    }
    If I put the annotion on the constructor argument
    data class Pet(@get:NonNull val names: List<String>)
    then it compiles to
    public final getNames()Ljava/util/List;
      @Lorg/eclipse/microprofile/graphql/NonNull;()
    as I would expect. Is it not possible to use use-site targets on types and type parameters? Is this a limitation/future feature/bug of the compiler? Or is the annotation missing a target (it has the target TYPE_USE)?
  • s

    smallshen

    09/14/2022, 5:04 AM
    Are there any plans to use MethodHandle for lambdas on JVM?
    i
    1 reply · 2 participants
  • i

    igor.wojda

    09/15/2022, 8:58 AM
    Hi I am using
    org.jetbrains.kotlin:kotlin-compiler
    to parse Kotlin files. I wonder is this lib intended also for file creation? I have a few parsed files (
    KtFile
    ) and I wonder if I can merge them - take imports, some top level members and create a new
    KtFile
    (that will be eventually saved to a disk) I wonder is it possible to take a
    KtFile
    as source for
    KtFile
    ? (initial ktfiles where created by parsing real kotlin from files from disk)
  • n

    nikolaymetchev

    09/15/2022, 2:32 PM
    I have a bug in the kotlin compiler in that it crashes with the following. How can I narrow it down to which file is causing the problem:
    java.lang.AssertionError: Number of arguments should not be less than number of parameters, but: parameters=3, args=2
    	at org.jetbrains.kotlin.types.IndexedParametersSubstitution.<init>(TypeSubstitution.kt:115)
    	at org.jetbrains.kotlin.types.IndexedParametersSubstitution.<init>(TypeSubstitution.kt:109)
    	at org.jetbrains.kotlin.types.IndexedParametersSubstitution.<init>(TypeSubstitution.kt:123)
    	at org.jetbrains.kotlin.types.TypeConstructorSubstitution$Companion.create(TypeSubstitution.kt:95)
    	at org.jetbrains.kotlin.types.KotlinTypeFactory.computeMemberScope(KotlinTypeFactory.kt:57)
    	at org.jetbrains.kotlin.types.KotlinTypeFactory.simpleType(KotlinTypeFactory.kt:90)
    	at org.jetbrains.kotlin.types.KotlinTypeFactory.simpleType$default(KotlinTypeFactory.kt:77)
    	at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.simpleType(TypeDeserializer.kt:127)
    	at org.jetbrains.kotlin.serialization.deserialization.TypeDeserializer.type(TypeDeserializer.kt:69)
    	at org.jetbrains.kotlin.serialization.deserialization.MemberDeserializer.loadFunction(MemberDeserializer.kt:218)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$OptimizedImplementation.computeFunctions(DeserializedMemberScope.kt:276)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$OptimizedImplementation.access$computeFunctions(DeserializedMemberScope.kt:228)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$OptimizedImplementation$functions$1.invoke(DeserializedMemberScope.kt:251)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$OptimizedImplementation$functions$1.invoke(DeserializedMemberScope.kt:251)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:651)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope$OptimizedImplementation.getContributedFunctions(DeserializedMemberScope.kt:329)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberScope.getContributedFunctions(DeserializedMemberScope.kt:82)
    	at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getContributedFunctions(DeserializedClassDescriptor.kt:315)
    	at org.jetbrains.kotlin.resolve.scopes.SubstitutingScope.getContributedFunctions(SubstitutingScope.kt:84)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getNonDeclaredFunctions(LazyClassMemberScope.kt:295)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.doGetFunctions(AbstractLazyMemberScope.kt:103)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.access$doGetFunctions(AbstractLazyMemberScope.kt:38)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope$functionDescriptors$1.invoke(AbstractLazyMemberScope.kt:51)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope$functionDescriptors$1.invoke(AbstractLazyMemberScope.kt:51)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
    	at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:651)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.getContributedFunctions(AbstractLazyMemberScope.kt:97)
    	at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope.getContributedFunctions(LazyClassMemberScope.kt:280)
    	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitNamedFunction(LazyDeclarationResolver.kt:125)
    	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver$resolveToDescriptor$1.visitNamedFunction(LazyDeclarationResolver.kt:94)
    	at org.jetbrains.kotlin.psi.KtNamedFunction.accept(KtNamedFunction.java:51)
    	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:94)
    	at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.resolveToDescriptor(LazyDeclarationResolver.kt:91)
    	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.createFunctionDescriptors(LazyTopDownAnalyzer.kt:284)
    	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:206)
    	at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations$default(LazyTopDownAnalyzer.kt:58)
    	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:130)
    	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:264)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:55)
    	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:255)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:101)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:60)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:157)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:94)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:477)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:127)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:366)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:311)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.rebuild(IncrementalCompilerRunner.kt:110)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:200)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:75)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:625)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1739)
    	at jdk.internal.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
    	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(AccessController.java:712)
    	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    	at java.base/java.lang.Thread.run(Thread.java:833)
    d
    14 replies · 2 participants
  • c

    Charlie Brown

    09/16/2022, 2:03 AM
    Hi guys, I want to know what exactly internal implement of SAM by check it decompiler but I don't know the meaning of this statement, could you please give me some idea about this. Thanks.
    static {
       samTwo = (SamTwoArg)null.INSTANCE;
    }
    Here is my original code (from Atomic Kotlin book)
    package interfaces
    import atomictest.eq
    
    fun interface SamTwoArg {
      fun h(i: Int, j: Int): Int
    }
    
    val samTwo =  SamTwoArg { i, j -> i + j }
    
    fun main() {
      samTwo.h(11, 47) eq 58
    }
    Here is decompiler result:
    // SamTwoArg.java
    package interfaces;
    
    import kotlin.Metadata;
    
    @Metadata(
       mv = {1, 5, 1},
       k = 1,
       d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\bæ\u0080\u0001\u0018\u00002\u00020\u0001J\u0018\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u0003H&¨\u0006\u0006"},
       d2 = {"Linterfaces/SamTwoArg;", "", "h", "", "i", "j", "AtomicKotlinCourse.main"}
    )
    public interface SamTwoArg {
       int h(int var1, int var2);
    }
    // SAMImplementationKt.java
    package interfaces;
    
    import atomictest.AtomicTestKt;
    import kotlin.Metadata;
    import org.jetbrains.annotations.NotNull;
    
    @Metadata(
       mv = {1, 5, 1},
       k = 2,
       d1 = {"\u0000\u0010\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0000\u001a\u0006\u0010\u0004\u001a\u00020\u0005\"\u0011\u0010\u0000\u001a\u00020\u0001¢\u0006\b\n\u0000\u001a\u0004\b\u0002\u0010\u0003¨\u0006\u0006"},
       d2 = {"samTwo", "Linterfaces/SamTwoArg;", "getSamTwo", "()Linterfaces/SamTwoArg;", "main", "", "AtomicKotlinCourse.main"}
    )
    public final class SAMImplementationKt {
       @NotNull
       private static final SamTwoArg samTwo;
    
       @NotNull
       public static final SamTwoArg getSamTwo() {
          return samTwo;
       }
    
       public static final void main() {
          AtomicTestKt.eq(samTwo.h(11, 47), 58);
       }
    
       // $FF: synthetic method
       public static void main(String[] var0) {
          main();
       }
    
       static {
          samTwo = (SamTwoArg)null.INSTANCE;
       }
    }
    s
    4 replies · 2 participants
  • p

    PHondogo

    09/21/2022, 6:14 AM
    Hello! How can I find out to what declaration expression belongs to? If it is impossible then is there IrElementTransformer that keeps track of element tree parent chain?
    s
    1 reply · 2 participants
  • n

    natario1

    09/23/2022, 9:22 AM
    Should the compiler throw or at least warn in this case?
    val list: List<Pair<String, Any>> = …
    val doubles = list.filterIsInstance<Pair<String, Double>>()
    filterIsInstance can’t check inner generic types, but this code is clean for both IDE and compiler.
    s
    e
    10 replies · 3 participants
  • p

    PHondogo

    09/24/2022, 9:31 AM
    Hello! I'm using IR compiler plugin for generation static fields for class. While for JVM backend it is ok. For JS backend I'm getting compiler error:
    java.lang.IllegalStateException: FULL: FIELD name:_GEN_ type:test.EnumTest visibility:internal [final,static]
     Ir: test.EnumTest.Companion._GEN_
     Descriptor: test.EnumTest.Companion#static{}_GEN_
    Stack trace in thread.
    1 reply · 1 participant
  • a

    August Lilleaas

    09/24/2022, 6:21 PM
    is it possible to create a class that somehow enforces non-lazy loading of all the classes that it uses in the compiled output? That might sound like a weird question… but the reason I need this, is that AWS Lambda cold starts perform much better when you do as much initialization as possible before it executes your handler function. By default, static blocks of the various classes I’m using in my lambda handler function runs only the first time the class is used. I would like to force it to run statically, alongside the static initialization of my main handler class. My current workaround is to manually load the classes I know that the handler function ends up loading. Which works, but is quite cumbersome 🙂
    class MyHandler :
        RequestHandler<Map<String, String>, String>
    {
        companion object {
            init {
                dataSource
                println(Intrinsics::class.java)
                println(Result::class.java)
                println(Session::class.java)
                println(::handleUserEmailSearch.toString())
                println(Continuation::class.java)
                println(Function::class.java)
                println(Unit::class.java)
            }
        }
    
        override fun handleRequest(input: Map<String, String>, context: Context): String {
            return serverlessWebResponseDb(dataSource) { dbSess ->
                handleUserEmailSearch(dbSess, input["email"])
            }
        }
    }
    b
    e
    +1
    31 replies · 4 participants
  • m

    majindong

    09/26/2022, 3:21 AM
    Hello everyone, I want to add a inner class using SyntheticResolveExtension, thus I need to add a constructor to the class. But I don't know how to add it successfully.
    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
    ) {
    
    }.apply {
    
      val a = ClassConstructorDescriptorImpl.create(
        this,
        Annotations.EMPTY,
        true,
        this.source
      )
      val b = a.initialize(
        emptyList(),
        DescriptorVisibilities.PUBLIC,
        emptyList(),
      )
    this.initialize(
        // 内部类的成员范围 MemberScope.Empty
        MemberScope.Empty,
        // 构造方法集合
        emptySet(),
        b
      )
    }
    d
    1 reply · 2 participants
  • m

    mbonnin

    09/27/2022, 3:25 PM
    Can I tell the compiler to ignore only a certain type of warnings? (deprecation in my case)
    s
    5 replies · 2 participants
  • a

    August Lilleaas

    09/29/2022, 4:46 PM
    what’s the type of a lambda expression when seen from Java? My actual question: is it possible to pass lambdas to Java code and retrieve them based on the type? For example, store a lambda in a Spring Context and then retrieve it using the type of the lambda expression somehow? The little digging I’ve been able to do gives me the impression that it’s not easily doable. For example,
    suspend
    is lost to the Java type system and seems to be compiled into coroutine-friendly code with no type info about it.
    s
    e
    7 replies · 3 participants
  • j

    Javier

    10/01/2022, 6:39 PM
    With Kotlin 1.7.10 I was able to get the correct line number of an inline function which is calling a log function via thread stacktrace. Previously to Kotlin 1.7+, this wasn't working, and now with Kotlin 1.7.20 it is not working anymore. Any workaround?
    c
    e
    10 replies · 3 participants
  • n

    Norbi

    10/04/2022, 8:55 AM
    Is it possible to get the
    KotlinType
    representation of an arbitrary type by fully qualified name in
    AnalysisHandlerExtension.analysisCompleted()
    ? Thanks.
  • m

    majindong

    10/06/2022, 9:11 AM
    How can I write a plugin to extends a father class automatically using SyntheticResolveExtension or IR ?
  • v

    vineethraj49

    10/06/2022, 3:37 PM
    can i compile something using kotlin-maven-plugin on jdk17, with source/target set to 8 and expect it to be binary compatible with jdk8?
    s
    2 replies · 2 participants
  • s

    Sean Proctor

    10/06/2022, 4:51 PM
    I'm getting an internal error trying to compile after adding an XML serializer https://gist.github.com/sproctor/540f023fd3507ac35bffd3827e412e55 It's likely I'm also doing something wrong with the serializer, this is my first attempt at it. Anyone have an idea how to work around this?
    d
    2 replies · 2 participants
  • r

    raulraja

    10/07/2022, 2:44 PM
    Hi!, I'm working on a compiler plugin in backend IR where I'm in need to move some statements from a user generated function to a plugin generated one. When I move the statements using
    IrElement.deepCopyWithSymbol
    I can properly clone the entire tree I need but this tree comes with proper offsets that I need to reset to
    UNDEFINED_OFFSET
    . I tried recursively walking the tree and mutating it but offsets are declared as a
    val
    and passed as arguments to most methods in
    irFactory
    . Is there a way to change the offsets of an existing IR Tree? Is there a way to clone a tree without the offsets? Thanks!
    i
    2 replies · 2 participants
  • g

    galex

    10/08/2022, 2:15 PM
    Hello, I am trying the new K2/FIR Compiler plugin API on Kotlin
    1.8.20-dev-649
    and I'm getting a
    NoClassDefFoundError: com/intellij/psi/PsiElement
    error. Thanks in advance 🙏
    d
    13 replies · 2 participants
  • r

    rkeazor

    10/09/2022, 4:39 PM
    Since the KotlinCompile Task no longer inherits from SourceTask in kotlin 1.7+, is there an equivalent way to set sources ,like you could do with SourceTask.source(...)?
    z
    1 reply · 2 participants
  • t

    Tyler Rockwood

    10/11/2022, 2:32 AM
    I'm looking into porting the Bazel Jdeps kotlin plugin to K2/FIR and would love some guidance (here is a historical post on this). Essentially this plugin needs to tie a symbol back to a jar on the classpath. The current plugin is here (registrar). I'm assuming some sort of "checker" is needed, probably
    declarationCheckers
    and
    expressionCheckers
    ? Once I've collected all of these I need to write the list of jars to a protocol buffer - the current plugin does this in
    analysisCompleted
    - is there a corresponding callback in k2 for when the "checker" is all done? Thanks for any insights 🙂
    d
    3 replies · 2 participants
  • s

    Stefan

    10/11/2022, 8:53 AM
    Hi, I found a bug in the JDK (
    java.lang.Class.getGenericSuperclass
    ) in an Kotlin only setup (reified types and spaces in method names). Where should I report a bug?
    s
    3 replies · 2 participants
  • p

    peekandpoke

    10/12/2022, 8:45 AM
    Hi! Anyone encountered this problem below? I have a multiplatform shared sub-project. And since 1.7.20 the incremental compilation sometimes has a hick-up:
    > Task :shared:api:compileKotlinJs FAILED
    e: Could not load module <com.thebase.shared:api> in an attempt to find deserializer for symbol com.thebase.shared.api.finance/FolioModel.BillingAddress.Company|null[0].
    When the cache is cleared things start to work again ...
    f
    d
    +1
    6 replies · 4 participants
  • m

    Marc Knaup

    10/16/2022, 11:16 AM
    Looks like
    @NoInfer
    is no longer working for builder patterns 👀 What’s the status of that annotation? When public? 😄
    1 reply · 1 participant
  • p

    PHondogo

    10/17/2022, 8:23 PM
    Hello! My code is compiling by Kotlin 1.7.10 but I see exceptions in output :
    Caught an exception trying to connect to Kotlin Daemon:
    java.lang.NoSuchFieldError: COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS
    What can be wrong?
  • j

    Jesper Åman

    10/19/2022, 8:33 PM
    Hi! Is it possible to control execution order of plugins? I want a plugin I'm working on to run after the Compose compiler plugin has finished running.
    y
    b
    4 replies · 3 participants
  • m

    Michal Fudala

    10/20/2022, 9:51 AM
    Hello 👋 Are there any compiler flags or plugins to improve performance when building projects with 10000+ kotlin files (generated code)? Each package is independent, meaning that it does not import anything from other packages (there are ~20 files per package). I wrote a script that essentially did
    kotlinc package1; kotlinc package2; kotlinc package3; ...
    in parallel and was able to get rid of the out of memory error. Are there any better alternatives? Can Gradle help me here?
  • p

    PHondogo

    10/20/2022, 12:54 PM
    Suppose function
    fun test(a: Int = <default value calculation>)
    And caller
    test(if (expr) 10 else <default value calculation> )
    It will be good if there was possibility to pass some keyword that is treated as default value that was declared in function. For example:
    test(if (expr) 10 else default)
    d
    2 replies · 2 participants
  • e

    Eduardo López

    10/21/2022, 1:35 PM
    Hi folks. I would like to achieve the following behaviour for the property below:
    var stringField: String?
        get() = unscoped { data: MyData ->
            data.getString()
        }
        set(value) = scoped { scope: MyScope ->
            scope.setString(value)
        }
    but I'm at a loss as to how to build the lambdas received by `scoped`/`unscoped` in IR. Any hints?
    n
    1 reply · 2 participants
Powered by Linen
Title
e

Eduardo López

10/21/2022, 1:35 PM
Hi folks. I would like to achieve the following behaviour for the property below:
var stringField: String?
    get() = unscoped { data: MyData ->
        data.getString()
    }
    set(value) = scoped { scope: MyScope ->
        scope.setString(value)
    }
but I'm at a loss as to how to build the lambdas received by `scoped`/`unscoped` in IR. Any hints?
n

natario1

10/21/2022, 5:42 PM
First you create a local function with local visibility, then wrap it in a IrFunctionExpression. I suggest you make a text search for IrFunctionExpressionImpl in the kotlin source code, to see how other plugins use it.
View count: 3