Hello there! I am trying to switch the Javascript ...
# javascript
p
Hello there! I am trying to switch the Javascript part of multi-platfatform library to IR. But now things do not compile anymore and I get the error below. Does anyone know what is going on there? Things work fine with the Legacy compiler.
Copy code
> Task :commonmp:compileKotlinJs FAILED
e: org.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration TypedAttributes
File being compiled: (3,1) in .../TypedAttributes.kt
The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:93)
        at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitDeclaration(ExceptionWrappingKtVisitorVoid.kt:43)
        at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:453)
        at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:21)
        at org.jetbrains.kotlin.psi.KtVisitor.visitNamedDeclaration(KtVisitor.java:398)
        ...
Caused by: java.lang.AssertionError: Built-in class kotlin.Any is not found
        at org.jetbrains.kotlin.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:93)
        at org.jetbrains.kotlin.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:88)
        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.builtins.KotlinBuiltIns.getBuiltInClassByName(KotlinBuiltIns.java:223)
        at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getAny(KotlinBuiltIns.java:228)
        ...
Here is the class that causes the compilation error. Any clue what I can do?
Copy code
package de.peekandpoke.ultra.common

/**
 * Map of [TypedKey] to values
 */
data class TypedAttributes internal constructor(val entries: Map<TypedKey<*>, Any?>) {

    companion object {
        /**
         * Empty instance
         */
        val empty = TypedAttributes(emptyMap())

        /**
         * Builder method
         */
        operator fun invoke(builder: Builder.() -> Unit) = of(builder)

        /**
         * Builder method
         */
        fun of(builder: Builder.() -> Unit) = Builder().apply(builder).build()
    }

    /**
     * Builder for [TypedAttributes]
     */
    class Builder {

        private val entries = mutableMapOf<TypedKey<*>, Any>()

        /**
         * Adds an entry by [key] and [value]
         */
        fun <T : Any> add(key: TypedKey<T>, value: T) {
            entries[key] = value
        }

        /**
         * Builds the [TypedAttributes] instance
         */
        fun build() = TypedAttributes(entries.toMap())
    }

    /**
     * Gets the number of entries
     */
    val size: Int = entries.size

    /**
     * Converts this to a mutable collection.
     */
    fun asMutable(): MutableTypedAttributes = MutableTypedAttributes(entries)

    /**
     * Gets an entry by [key] or null if nothing is there
     */
    operator fun <T : Any> get(key: TypedKey<T>): T? {
        @Suppress("UNCHECKED_CAST")
        return entries[key] as T?
    }

    /**
     * Adds an entry by [key] and [value] and returns a new instance of [TypedAttributes]
     */
    fun <T : Any> plus(key: TypedKey<T>, value: T) = TypedAttributes(
        entries.plus(key to value)
    )
}