utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
637 stars 46 forks source link

Incorrect CoreType warning on variable modification #347

Closed tomwyr closed 2 years ago

tomwyr commented 2 years ago

Following snippet produces a warning which doesn't seem to be correct:

class Simple {
    var number = IntHolder().intValue.toDouble()

    fun updateNumber() {
        number = 5.0
    }
}

class IntHolder {
    val intValue = 1
}

gives a warning on number = 5.0:

You're modifying a copy of a CoreType. Either re assign this copy to it's parent or use it elsewhere after the modification.For more information's, visit the documentation.This warning is experimental! If you encounter any false positives, please write an issue with a minimal reproduction project.

The warning shows up only, if the Int -> Double type conversion happens during number initialization.

tomwyr commented 2 years ago

Same issue but slightly different code:

class Simple {
    var number = Wrapper.intHolder.intValue

    fun updateNumber() {
        number = 5
    }
}

object Wrapper {
    val intHolder = IntHolder()
}

class IntHolder {
    val intValue = 1
}
piiertho commented 2 years ago

@chippmann