gammax
01/29/2021, 5:40 PMcompiler-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:
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.dmitriy.novozhilov
01/29/2021, 6:57 PMErrorType
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 PRgammax
01/29/2021, 6:59 PMdmitriy.novozhilov
01/29/2021, 7:00 PMDiagnosticTestGenerated
and DiagnosticsTestSpecGenerated
should be enoughgammax
01/29/2021, 7:01 PMdmitriy.novozhilov
01/29/2021, 7:02 PMgammax
01/29/2021, 7:02 PMgammax
02/01/2021, 11:02 PM