I found an “interesting scenario” for the `compile...
# compiler
g
I found an “interesting scenario” for the 
compiler-embeddable
 . I would like to get some opinions on it, understand if it’s a bug, where to report it and eventually push a fix upstream. The issue happened on one of our #detekt rule (here the patch on our end) The snippet to reproduce is:
Copy code
import com.sample.function.from.outside

fun test() {
    val a = outside()
    val b = a?.plus(42)
}
If the external function is not provided during the compilation, the Kotlin compiler is raising an 
UNNECESSARY_SAFE_CALL
 on 
a?.plus
. The type of 
a
 is 
org.jetbrains.kotlin.types.ErrorType
 . My hunch is that the compiler should not report this error if they information on the type is missing.
d
It's not a bug. As you correctly noticed compiler creates
ErrorType
for types which can not be resolved. Those types has no member scope, they are not equal to anything or not subtype of anything. But every type in kotlin type system should have a nullability and for
ErrorType
it is
NOT_NULL
. Actually there is no meaning in it, but some nullability should be choosen IMO there is no problem with it, because this is a diagnostic which was produced by some error in user code earlier, and fixing original error will fix that one too But if you want you may find a reporter of
UNNECESSARY_SAFE_CALL
, fix it so it won't report diagnostic on call if receiver is an error type and send a PR
g
Thanks for the insights 👌 I’ll try to send a PR then
d
Don't forget to check that all tests pass after your fix. Running
DiagnosticTestGenerated
and
DiagnosticsTestSpecGenerated
should be enough
g
Great thanks for the pointers 🙏 Should I also open an issue somewhere as a reference?
d
You can just attach link to this thread to PR Also you can ping me here when PR will be ready
g
Great, thanks 👍