Do not report UNNECESSARY_SAFE_CALL on ErrorType

This commit is contained in:
Nicola Corti
2021-02-01 23:50:07 +01:00
committed by TeamCityServer
parent 59551eb037
commit e2b7aba086
6 changed files with 39 additions and 7 deletions
@@ -686,6 +686,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.kt");
}
@Test
@TestMetadata("SafeCallUnknownType.kt")
public void testSafeCallUnknownType() throws Exception {
runTest("compiler/testData/diagnostics/tests/SafeCallUnknownType.kt");
}
@Test
@TestMetadata("Serializable.kt")
public void testSerializable() throws Exception {
@@ -67,6 +67,7 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.refinement.TypeRefinement
import javax.inject.Inject
@@ -534,15 +535,17 @@ class CallExpressionResolver(
} ?: false
fun reportUnnecessarySafeCall(
trace: BindingTrace, type: KotlinType,
callOperationNode: ASTNode, explicitReceiver: Receiver?
) = trace.report(
trace: BindingTrace,
type: KotlinType,
callOperationNode: ASTNode,
explicitReceiver: Receiver?
) {
if (explicitReceiver is ExpressionReceiver && explicitReceiver.expression is KtSuperExpression) {
UNEXPECTED_SAFE_CALL.on(callOperationNode.psi)
} else {
UNNECESSARY_SAFE_CALL.on(callOperationNode.psi, type)
trace.report(UNEXPECTED_SAFE_CALL.on(callOperationNode.psi))
} else if (!type.isError) {
trace.report(UNNECESSARY_SAFE_CALL.on(callOperationNode.psi, type))
}
)
}
private fun checkNestedClassAccess(
expression: KtQualifiedExpression,
@@ -0,0 +1,7 @@
// !WITH_NEW_INFERENCE
import com.unknown
fun ff() {
val a = <!UNRESOLVED_REFERENCE!>unknown<!>()
val b = a?.plus(42)
}
@@ -0,0 +1,7 @@
// !WITH_NEW_INFERENCE
import <!UNRESOLVED_REFERENCE!>com<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>unknown<!>
fun ff() {
val a = <!UNRESOLVED_REFERENCE!>unknown<!>()
val <!UNUSED_VARIABLE!>b<!> = <!TYPE_MISMATCH{OI}!><!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>?.<!DEBUG_INFO_MISSING_UNRESOLVED!>plus<!>(42)<!>
}
@@ -0,0 +1,3 @@
package
public fun ff(): kotlin.Unit
@@ -686,6 +686,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/SafeCallOnSuperReceiver.kt");
}
@Test
@TestMetadata("SafeCallUnknownType.kt")
public void testSafeCallUnknownType() throws Exception {
runTest("compiler/testData/diagnostics/tests/SafeCallUnknownType.kt");
}
@Test
@TestMetadata("Serializable.kt")
public void testSerializable() throws Exception {