In the case of kotlin, rust and many other programming languages...
There are variables with direct implicit type declarations... Where you can see the type of a variable at the same line where it's defined and initialized.
val a = 1
if you change this code to this...
val a = 1.5f
the change can be easily addressed down the function where this variable is used...
Now if we look at this code...
fun f(): <first type> {
return ...
}
val d = f()
val e = f2()
and if you change return type of function to this...
fun f(): <other type compatible with first type> {
return ...
}
val d = f() <--- Still compiles but the change is not being addressed by the programmer.
val e = f2()
All variables that store return type from the function and are defined with indirect implicit type declaration will not be addressed by the programmer and this will result in a vulnerable, fragile, or even dangerous codebase over time...
My question is similar to:
- Explicitly defining variable data types vs. using the keyword 'var'?
- why-kotlin-doesnt-have-explicit-typing
- when-is-it-a-good-idea-to-include-explicit-type-declarations-in-kotlin
But my problem is about the indirect implicit variable declarations where you store the return type of a function to a variable with an implicit declaration which I think is dangerous and the compiler should not allow this kind of implicit declaration.
What are you guys thinking? Should be this problem addressed on the compiler level or I'm overreacting?