[FIR] Prevent replacing UNNECESSARY_SAFE_CALL with UNEXPECTED_SAFE_CALL
UNNECESSARY_SAFE_CALL is a warning, UNEXPECTED_SAFE_CALL is an error, thus it's a breaking change. Also see KT-60695. ^KT-59860 Fixed Merge-request: KT-MR-11210 Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
cd073690fa
commit
57908eba77
+6
@@ -1245,6 +1245,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unexpectedSafeCall.kt")
|
||||||
|
public void testUnexpectedSafeCall() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/unexpectedSafeCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
||||||
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
||||||
|
|||||||
+6
@@ -1245,6 +1245,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unexpectedSafeCall.kt")
|
||||||
|
public void testUnexpectedSafeCall() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/unexpectedSafeCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
||||||
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
||||||
|
|||||||
+6
@@ -1245,6 +1245,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unexpectedSafeCall.kt")
|
||||||
|
public void testUnexpectedSafeCall() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/unexpectedSafeCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
||||||
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
||||||
|
|||||||
+6
@@ -1245,6 +1245,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unexpectedSafeCall.kt")
|
||||||
|
public void testUnexpectedSafeCall() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/unexpectedSafeCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
||||||
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
||||||
|
|||||||
+6
-1
@@ -12,8 +12,13 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
|
import org.jetbrains.kotlin.fir.expressions.FirSafeCallExpression
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.calleeReference
|
||||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||||
|
import org.jetbrains.kotlin.fir.references.resolved
|
||||||
|
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeErrorType
|
||||||
import org.jetbrains.kotlin.fir.types.canBeNull
|
import org.jetbrains.kotlin.fir.types.canBeNull
|
||||||
import org.jetbrains.kotlin.fir.types.coneType
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
import org.jetbrains.kotlin.fir.types.isUnit
|
import org.jetbrains.kotlin.fir.types.isUnit
|
||||||
@@ -21,7 +26,7 @@ import org.jetbrains.kotlin.fir.types.isUnit
|
|||||||
object FirUnnecessarySafeCallChecker : FirSafeCallExpressionChecker() {
|
object FirUnnecessarySafeCallChecker : FirSafeCallExpressionChecker() {
|
||||||
override fun check(expression: FirSafeCallExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirSafeCallExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
val receiverType = expression.receiver.typeRef.coneType.fullyExpandedType(context.session)
|
val receiverType = expression.receiver.typeRef.coneType.fullyExpandedType(context.session)
|
||||||
if (receiverType.isUnit || expression.receiver.source?.elementType == KtNodeTypes.SUPER_EXPRESSION) {
|
if (expression.receiver.source?.elementType == KtNodeTypes.SUPER_EXPRESSION) {
|
||||||
reporter.reportOn(expression.source, FirErrors.UNEXPECTED_SAFE_CALL, context)
|
reporter.reportOn(expression.source, FirErrors.UNEXPECTED_SAFE_CALL, context)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ val s: String = "test"
|
|||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
fun ff() {
|
fun ff() {
|
||||||
val a = <!NO_COMPANION_OBJECT!>Test<!><!UNEXPECTED_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>FOO<!>
|
val a = <!NO_COMPANION_OBJECT!>Test<!><!UNNECESSARY_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>FOO<!>
|
||||||
val b = <!EXPRESSION_EXPECTED_PACKAGE_FOUND!>foo<!><!UNEXPECTED_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>s<!>
|
val b = <!EXPRESSION_EXPECTED_PACKAGE_FOUND!>foo<!><!UNNECESSARY_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>s<!>
|
||||||
<!NO_COMPANION_OBJECT!>System<!><!UNEXPECTED_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>out<!>.println(a + b)
|
<!NO_COMPANION_OBJECT!>System<!><!UNNECESSARY_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>out<!>.println(a + b)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val b: Int
|
val b: Int
|
||||||
run { b = 1 }<!UNEXPECTED_SAFE_CALL!>?.<!>let {}
|
run { b = 1 }<!UNNECESSARY_SAFE_CALL!>?.<!>let {}
|
||||||
b.inc()
|
b.inc()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
|
||||||
|
// ISSUE: KT-59860
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val b: Int
|
||||||
|
run { b = 1 }<!UNNECESSARY_SAFE_CALL!>?.<!>let {} // K1: UNNECESSARY_SAFE_CALL, K2: UNEXPECTED_SAFE_CALL
|
||||||
|
}
|
||||||
+2
-2
@@ -6,7 +6,7 @@ public class Test {
|
|||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
fun ff() {
|
fun ff() {
|
||||||
val a = Test.FOO
|
val a = Test.FOO
|
||||||
val b = <!NO_COMPANION_OBJECT!>Test<!><!UNEXPECTED_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>FOO<!>
|
val b = <!NO_COMPANION_OBJECT!>Test<!><!UNNECESSARY_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>FOO<!>
|
||||||
System.out.println(a + b)
|
System.out.println(a + b)
|
||||||
<!NO_COMPANION_OBJECT!>System<!><!UNEXPECTED_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>out<!>.println(a + b)
|
<!NO_COMPANION_OBJECT!>System<!><!UNNECESSARY_SAFE_CALL!>?.<!><!UNRESOLVED_REFERENCE!>out<!>.println(a + b)
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+6
@@ -1245,6 +1245,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
runTest("compiler/testData/diagnostics/tests/UnderscoreUsageInVariableAsFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unexpectedSafeCall.kt")
|
||||||
|
public void testUnexpectedSafeCall() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/unexpectedSafeCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
@TestMetadata("UnitByDefaultForFunctionTypes.kt")
|
||||||
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
public void testUnitByDefaultForFunctionTypes() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user