Hi there! I have a very annoying internal compiler...
# multiplatform
p
Hi there! I have a very annoying internal compiler error here, which happens while compiling JS in a multiplatform project. Here is the Stacktrace:
Copy code
> Task :common:compileKotlinJs FAILED
e: org.jetbrains.kotlin.util.FileAnalysisException: Somewhere in file [...]/src/commonMain/kotlin/common/datetime/KronosDescriptor.kt: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
        at org.jetbrains.kotlin.util.AnalysisExceptionsKt.wrapIntoFileAnalysisExceptionIfNeeded(AnalysisExceptions.kt:62)
        at org.jetbrains.kotlin.fir.FirCliExceptionHandler.handleExceptionOnFileAnalysis(Utils.kt:249)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverTransformer.transformFile(FirSupertypesResolution.kt:883)
        at org.jetbrains.kotlin.fir.declarations.FirFile.transform(FirFile.kt:46)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor.processFile(FirResolveProcessor.kt:48)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveProcessor.process(FirTotalResolveProcessor.kt:36)
        at org.jetbrains.kotlin.fir.pipeline.AnalyseKt.runResolution(analyse.kt:20)
        at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.resolveAndCheckFir(firUtils.kt:76)
        at org.jetbrains.kotlin.fir.pipeline.FirUtilsKt.buildResolveAndCheckFirViaLightTree(firUtils.kt:88)
        at org.jetbrains.kotlin.cli.js.klib.JsCompilerPipelineKt.compileModulesToAnalyzedFirWithLightTree(jsCompilerPipeline.kt:195)
        at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.processSourceModuleWithK2(K2JsIrCompiler.kt:595)
        at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.produceSourceModule(K2JsIrCompiler.kt:496)
        at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:327)
        at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:70)
        at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:33)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:103)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:49)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
        at org.jetbrains.kotlin.incremental.IncrementalJsCompilerRunner.runCompiler(IncrementalJsCompilerRunner.kt:211)
        at org.jetbrains.kotlin.incremental.IncrementalJsCompilerRunner.runCompiler(IncrementalJsCompilerRunner.kt:86)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
        at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile$default(IncrementalCompilerRunner.kt:113)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execJsIncrementalCompiler(CompileServiceImpl.kt:609)
        at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execJsIncrementalCompiler(CompileServiceImpl.kt:92)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1758)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        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:840)
Caused by: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
        at org.jetbrains.kotlinx.serialization.compiler.fir.SerializationFirUtilsKt.createDeprecatedHiddenAnnotation(SerializationFirUtils.kt:315)
        at org.jetbrains.kotlinx.serialization.compiler.fir.SerializationFirUtilsKt.markAsDeprecatedHidden(SerializationFirUtils.kt:336)
        at org.jetbrains.kotlinx.serialization.compiler.fir.SerializationFirResolveExtension.generateSerializerImplClass(SerializationFirResolveExtension.kt:322)
        at org.jetbrains.kotlinx.serialization.compiler.fir.SerializationFirResolveExtension.generateNestedClassLikeDeclaration(SerializationFirResolveExtension.kt:77)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedMemberDeclarationsStorage$ClassifierStorage.generateNestedClassifier(FirGeneratedScopes.kt:239)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedMemberDeclarationsStorage$ClassifierStorage.access$generateNestedClassifier(FirGeneratedScopes.kt:216)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedMemberDeclarationsStorage$ClassifierStorage$special$$inlined$createCache$1.invoke(FirCachesFactory.kt:73)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedMemberDeclarationsStorage$ClassifierStorage$special$$inlined$createCache$1.invoke(FirCachesFactory.kt:71)
        at org.jetbrains.kotlin.fir.caches.FirThreadUnsafeCache.getValue(FirThreadUnsafeCachesFactory.kt:40)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedClassNestedClassifierScope.getNestedClassSymbol(FirGeneratedScopes.kt:281)
        at org.jetbrains.kotlin.fir.scopes.impl.FirGeneratedClassNestedClassifierScope.getNestedClassSymbol(FirGeneratedScopes.kt:96)
        at org.jetbrains.kotlin.fir.scopes.impl.FirNestedClassifierScope.processClassifiersByNameWithSubstitution(FirNestedClassifierScope.kt:36)
        at org.jetbrains.kotlin.fir.scopes.impl.FirCompositeNestedClassifierScope.processClassifiersByNameWithSubstitution(FirNestedClassifierScope.kt:89)
        at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScopeImpl.processClassifiersByNameWithSubstitution(FirClassDeclaredMemberScope.kt:90)
        at org.jetbrains.kotlin.fir.extensions.GeneratedDeclarationsUtilsKt.generatedNestedClassifiers(generatedDeclarationsUtils.kt:54)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.addSupertypesToGeneratedNestedClasses(FirSupertypesResolution.kt:510)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.resolveSpecificClassLikeSupertypes$lambda$15(FirSupertypesResolution.kt:482)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.resolveSpecificClassLikeSupertypes(FirSupertypesResolution.kt:405)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.resolveSpecificClassLikeSupertypes(FirSupertypesResolution.kt:448)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitRegularClass(FirSupertypesResolution.kt:428)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitRegularClass(FirSupertypesResolution.kt:228)
        at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
        at org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl.acceptChildren(FirRegularClassImpl.kt:63)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitDeclarationContent(FirSupertypesResolution.kt:416)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitRegularClass(FirSupertypesResolution.kt:429)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitRegularClass(FirSupertypesResolution.kt:228)
        at org.jetbrains.kotlin.fir.declarations.FirRegularClass.accept(FirRegularClass.kt:48)
        at org.jetbrains.kotlin.fir.declarations.impl.FirFileImpl.acceptChildren(FirFileImpl.kt:57)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitDeclarationContent(FirSupertypesResolution.kt:416)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitFile(FirSupertypesResolution.kt:595)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverVisitor.visitFile(FirSupertypesResolution.kt:228)
        at org.jetbrains.kotlin.fir.declarations.FirFile.accept(FirFile.kt:42)
        at org.jetbrains.kotlin.fir.resolve.transformers.FirSupertypeResolverTransformer.transformFile(FirSupertypesResolution.kt:73)
        ... 42 more
And here is the class it tries to compile:
Copy code
package de.peekandpoke.ultra.common.datetime

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
sealed interface KronosDescriptor {

    @SerialName("system-clock")
    @Serializable
    object SystemClock : KronosDescriptor

    @SerialName("advanced-by")
    @Serializable
    data class AdvancedBy(
        val durationMs: Long,
        val inner: KronosDescriptor,
    ) : KronosDescriptor

    /**
     * Creates a [Kronos] from the given descriptor
     */
    fun instantiate(): Kronos {
        return Kronos.from(this)
    }
}
This is very strange... it worked and then it suddenly stopped working. This is happening for Kotlin version 2.0.0 up to 2.1.10. I tried clearing all caches, project and gradle cache. Does not help. I am completely stuck! Does anyone have a least a work-around. I find it very hard to keep using Kotlin, when these kinds of things keep happening again and again. With every major language version update, we ran into these kinds of problems, usually related to KotlinJS.
🧵 7
If you want to reproduce this, then check out this repo on the branch `kotlin-2.1-compiler-error`: https://github.com/PeekAndPoke/ultra/tree/kotlin-2.1-compiler-error then run:
Copy code
./gradlew :common:assemble
t
cc @Artem Kobzar
a
Thank you @peekandpoke for sharing the issue. We've never met it, so may I ask you to create a YouTrack issue here with the description and reproducer you've created to you can track the progress on the problem?
p
Hi! Thanks for picking this up. Nevertheless I am stuck on my work. Do you have any quick-fix for this? @Artem Kobzar
Could you also please send the link to the ticket. The one above does not work
Ahh .. you want me to create the ticket ... i see
a
I'm investigating the problem. It seems like it doesn't related to your class but can't find a standard
Deprecated
annotation. Could you please share your build.gradle.kts (if it's possible)
Never mind, I will create the ticket. 🫡
p
thx
a
@sandwwraith have you ever met the problem? Based on the stacktrace, it looks like here:
Copy code
val deprecatedAnno =
        session.symbolProvider.getClassLikeSymbolByClassId(StandardClassIds.Annotations.Deprecated) as FirRegularClassSymbol
the
deprecatedAnno
is
null
1
@peekandpoke is it possible to take a look at your
build.gradle.kts
?
p
sure
Copy code
@file:Suppress("PropertyName")

import Deps.Test.commonTestDeps
import Deps.Test.configureJvmTests
import Deps.Test.jsTestDeps
import Deps.Test.jvmTestDeps

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.kotlin.plugin.serialization")
    id("io.kotest.multiplatform")
    id("org.jetbrains.dokka")
    id("com.vanniktech.maven.publish")
}

val GROUP: String by project
val VERSION_NAME: String by project

group = GROUP
version = VERSION_NAME

repositories {
    mavenCentral()
}

kotlin {

    js {
        browser {
        }
    }

    jvmToolchain(Deps.jvmTargetVersion)

    jvm {
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation(kotlin("reflect"))
                implementation(Deps.kotlinx_coroutines_core)
                implementation(Deps.kotlinx_serialization_core)
                implementation(Deps.kotlinx_serialization_json)

                implementation(Deps.ktor_client_core)

                // We expose kotlinx-datetime as it is needed in many cases, e.g. for TimeZone
                api(Deps.kotlinx_datetime)

                // TODO: Remove this dependency
                //       It is still needed for formatting dates
                implementation(Deps.korlibs_time)
            }
        }

        commonTest {
            dependencies {
                commonTestDeps()
            }
        }

        jsMain {
            dependencies {
                api(Deps.Npm { polyfillFetch() })
                api(Deps.Npm { jsJodaCore() })
                api(Deps.Npm { jsJodaTimezone() })
            }
        }

        jsTest {
            dependencies {
                jsTestDeps()
            }
        }

        jvmMain {
            dependencies {
                implementation(Deps.classindex)
            }
        }

        jvmTest {
            dependencies {
                jvmTestDeps()
            }
        }
    }
}

tasks {
    configureJvmTests()
}
a
Is it an open-source project? Can I build it by myself to deeper understand the issue?
p
yes
Please check above. I posted a link to the repo and the branch on which you will be able to reproduce
thank you color 1
👍 1
a
It's weird. Everything is built fine on my laptop. I only found the problem with clashing files on macOS:
src/jvmMain/kotlin/lib/Mutator.kt
and
src/jvmMain/kotlin/lib/mutator.kt
If you have time we can together (on a call) check what's going wrong on your machine.
p
That would be great!
Big shout-out to @Artem Kobzar! He helped me solve the issue in person. This is a really nice experience.
If you wonder what the issue was, here it is:
1. I had published the project to my local maven. 2. I had the
mavenLocal()
in the gradle repos as the first entry 3. this lead to gradle picking up some outdated kotlin-stdlib
...
So putting the
mavenLocal()
at the end of the repositories like this
Copy code
allprojects {
    repositories {
        mavenCentral()
        // KotlinX
        maven("<https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven>")
        // Snapshots
        maven("<https://oss.sonatype.org/content/repositories/snapshots>")
        // Local
        mavenLocal()
    }
}
And deleting
~/.m2
solved the issue
a
There are a few interesting links: • A guide to configure a Gradle project which includes the recommendation for the `mavenLocal`: https://kotlinlang.org/docs/gradle-configure-project.html#declare-repositories • The developer experience with the issue is not great at all and we're considering it and want to detect such a problem during configuration to notify you about such a situation. You can follow the task https://youtrack.jetbrains.com/issue/KT-66521 to check the progress on this work