Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Compilation failed: null with Kotlin 1.3.40 #3109

Closed
jcraane opened this issue Jun 25, 2019 · 11 comments
Closed

Compilation failed: null with Kotlin 1.3.40 #3109

jcraane opened this issue Jun 25, 2019 · 11 comments
Assignees

Comments

@jcraane
Copy link

jcraane commented Jun 25, 2019

We migrated our Kotlin multiplatform project from 1.3.21 to 1.3.40 (and updated all dependencies accordingly) and now we get the following error when compiling the common Kotlin code to IOS native:

> Task :common:linkDebugFrameworkIos
e: Compilation failed: null

e: kotlin.KotlinNullPointerException
	at org.jetbrains.kotlin.backend.konan.optimizations.ModuleDFGBuilder$FunctionDFGBuilder.getNode(DFGBuilder.kt:516)

There are lots of classes in our common code so it is not easy to determine what causes the error. Adding --info or --debug does not provide much more info.

Is there a preferred way of debugging these kind of issues? I can copy the code to a minimal project and then manually removing classes to see when it will work but this is quite tedious.

Thanks!

@homuroll
Copy link
Contributor

Please try compile with option -Xdisable-phases=Devirtualization,BuildDFG or with gradle:

compilations.all {
    kotlinOptions {
        freeCompilerArgs += "-Xdisable-phases=Devirtualization,BuildDFG"
    }
}

and tell us if it helps or not.

@jcraane
Copy link
Author

jcraane commented Jun 25, 2019

I am not sure where to put that configuration. I get a message compilations is an unknown property (in gradle). Apart from this I was able to localize this issue: The following construction does compile/run on the JVM but gives a NullPointerException when compiling to native:

import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

@Serializable
data class CachedItem(var data: String) {
    @Transient
    var timeProvider = RealtimeProvider()
    var creationTime = timeProvider.getNow()
}

class RealtimeProvider {
    fun getNow() = 100L
}

If I remove the dependency on the timeProvider in the initialization of the creationTime property, the code does compile.

I can workaround this issue but should this scenario be supported (it was working in 1.3.21)?

@homuroll
Copy link
Contributor

Looks like a bug in the serialization plugin. @sandwwraith will look at it.

@NiKlimenko
Copy link

@jcraane seems you are trying to serialize the creationTime property which depends on timeProvider that you skipped for serialization.

@jcraane
Copy link
Author

jcraane commented Jun 27, 2019

That is correct indeed. But serializing/deserializing works on the JVM in this case but the compilation phase to IOS/native code fails. This was working with kotlin 1.3.21. If I remove the @serializable, compilation to native code works (but than I cannot deserialize/serialize it from/to JSON of course).

@olonho
Copy link
Contributor

olonho commented Jun 28, 2019

This is an issue of https://github.com/Kotlin/kotlinx.serialization compiler plugin, so would be better to move discussing the problem there.

@webfrea-k
Copy link

@homuroll I've tried to add "-Xdisable-phases=Devirtualization,BuildDFG" as you suggested. The command leads to another error:

* Compiler version info: Konan: 1.3 / Kotlin: 1.3.40
 * Output kind: FRAMEWORK

e: java.lang.UnsupportedOperationException: org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl@4ab32a94

Hope this helps, otherwise I'll wait for the kotlinx.serialization fix.

@sandwwraith
Copy link
Member

I can confirm that the problem is caused by creationTime dependent on timeProvider variable. Such code causes problems in the serialization plugin now.

@webfrea-k
Copy link

@sandwwraith can anything else cause this? We have a lot of classes too, but I don't think there is a single case where child class would not be marked as @serializable (all the classes top-down are serializable in our case).

@edenman
Copy link

edenman commented Feb 18, 2021

I know it's been a couple years, but I'm seeing the same issue https://youtrack.jetbrains.com/issue/KTOR-2174

@SvyatoslavScherbina
Copy link
Collaborator

We are migrating issue tracking to YouTrack, so I'm closing this issue in favour of KT-45044.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants