mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-17 00:21:27 +00:00
[NI] Add missing diagnostic on callable references in fake calls
Unresolved reference diagnositc was not reported on callable references returned from if or when expression because of additional block wrapper. ^KT-30953 Fixed
This commit is contained in:
@@ -17801,6 +17801,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceInCST.kt")
|
||||
public void testCallableReferenceInCST() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypesInLambdaParameter.kt")
|
||||
public void testCapturedTypesInLambdaParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt");
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class DiagnosticReporterByTrackingStrategy(
|
||||
@@ -132,8 +133,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
trace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(callArgument.psiCallArgument.valueArgument.asElement()))
|
||||
|
||||
NoneCallableReferenceCandidates::class.java -> {
|
||||
val expression =
|
||||
(diagnostic as NoneCallableReferenceCandidates).argument.psiExpression.safeAs<KtCallableReferenceExpression>()
|
||||
val expression = diagnostic.cast<NoneCallableReferenceCandidates>()
|
||||
.argument.safeAs<CallableReferenceKotlinCallArgumentImpl>()?.ktCallableReferenceExpression
|
||||
reportIfNonNull(expression) {
|
||||
trace.report(UNRESOLVED_REFERENCE.on(it.callableReference, it.callableReference))
|
||||
}
|
||||
|
||||
36
compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.kt
vendored
Normal file
36
compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.kt
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun testWhen(x: Any?) {
|
||||
val y = when (x) {
|
||||
null -> ""
|
||||
else -> ::<!UNRESOLVED_REFERENCE!>unresolved<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun testWhenWithBraces(x: Any?) {
|
||||
val z = when(x) {
|
||||
null -> { "" }
|
||||
else -> { ::<!UNRESOLVED_REFERENCE!>unresolved<!> }
|
||||
}
|
||||
}
|
||||
|
||||
fun testIf(x: Any?) {
|
||||
val y = if (x != null) ::<!UNRESOLVED_REFERENCE!>unresolved<!> else null
|
||||
}
|
||||
|
||||
fun testIfWithBraces(x: Any?) {
|
||||
val z = if (x != null) { ::<!UNRESOLVED_REFERENCE!>unresolved<!> } else { null }
|
||||
}
|
||||
|
||||
fun testElvis(x: Any?) {
|
||||
val y = x ?: ::<!UNRESOLVED_REFERENCE!>unresolved<!>
|
||||
}
|
||||
|
||||
fun testExclExcl() {
|
||||
val y = :: <!UNRESOLVED_REFERENCE!>unresolved<!><!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NOT_NULL_ASSERTION_ON_CALLABLE_REFERENCE!>!!<!>
|
||||
}
|
||||
|
||||
fun testTry() {
|
||||
val v = try { ::<!UNRESOLVED_REFERENCE!>unresolved<!> } catch (e: Exception) {}
|
||||
}
|
||||
9
compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.txt
vendored
Normal file
9
compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.txt
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public fun testElvis(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testExclExcl(): kotlin.Unit
|
||||
public fun testIf(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testIfWithBraces(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testTry(): kotlin.Unit
|
||||
public fun testWhen(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
public fun testWhenWithBraces(/*0*/ x: kotlin.Any?): kotlin.Unit
|
||||
@@ -17813,6 +17813,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceInCST.kt")
|
||||
public void testCallableReferenceInCST() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypesInLambdaParameter.kt")
|
||||
public void testCapturedTypesInLambdaParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt");
|
||||
|
||||
@@ -17803,6 +17803,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/anonymousObjectFromTopLevelMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceInCST.kt")
|
||||
public void testCallableReferenceInCST() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("capturedTypesInLambdaParameter.kt")
|
||||
public void testCapturedTypesInLambdaParameter() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/resolve/capturedTypesInLambdaParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user