https://kotlinlang.org logo
#announcements
Title
# announcements
j

jtonic

12/07/2017, 6:05 AM
Dear Kt community, Could you please emphasise why the following compilation error occurs.
Error:(13, 30) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
in the following case
Copy code
package ro.jtonic.tutorials.kt.oop.miscs

private const val PI = Math.PI
const val E = Math.E

private fun computePi() = PI
fun computeE() = E

class MyMath {

    val E = FilePrivateUtils@::E.get() // here is the compilation error
    val pi = FilePrivateUtils@::PI.get()

    fun computingPi() = FilePrivateUtils@::computePi.invoke()
    fun computingE() = FilePrivateUtils@::computeE.invoke()
}
Thank you.
If I apply the Idea suggestion
val E: Double = FilePrivateUtils@::E.get()
then the value is 0 instead of value of e. the only thing to do (for me) is to rename the field as e. But I don’t like to have this especially for the class functions.
a

adam-mcneilly

12/07/2017, 6:11 AM
If it's running into a recursive problem, then I think it might be trying to reference the
E
that you're assigning, and not the
E
that's in your private utils. Also, for my own curiosity, why are you assigning
Math.e
to a val, and then having a function that returns it? Why not just reference
Math.E
inside
MyMath
whenever you need it?
j

jtonic

12/07/2017, 6:15 AM
I am learning kotlin language and I am on private private constants and functions. Disregard the values.
The thing is, how can assign the private constants in kt file from a class (same file) field having the same name.
I was under the impression that MyClass@ allows to access the things from the enclosing scope.
i

ilya.gorbunov

12/07/2017, 11:29 AM
MyClass@ is a label with the name MyClass
So basically you're just introducing 4 unrelated labels named
FilePrivateUtils