diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 56e78dd719f..67a6c4669ed 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -1854,6 +1854,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/callableReference/kt32267.kt"); } + @TestMetadata("kt34314.kt") + public void testKt34314() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314.kt"); + } + + @TestMetadata("kt34314_lambda.kt") + public void testKt34314_lambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt"); + } + @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index f94ff58b111..0755d4a28e2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -373,8 +373,12 @@ class DiagnosticReporterByTrackingStrategy( } ) return - val call = error.resolvedAtom.atom?.safeAs()?.psiCall ?: call - val expression = call.calleeExpression ?: return + val expression = when (val atom = error.resolvedAtom.atom) { + is PSIKotlinCall -> atom.psiCall.calleeExpression + is PSIKotlinCallArgument -> atom.valueArgument.getArgumentExpression() + else -> call.calleeExpression + } ?: return + val typeVariableName = when (val typeVariable = error.typeVariable) { is TypeVariableFromCallableDescriptor -> typeVariable.originalTypeParameter.name.asString() is TypeVariableForLambdaReturnType -> "return type of lambda" diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314.fir.kt new file mode 100644 index 00000000000..6703cd814a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314.fir.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun main() { + val x = run { ::run } // no error +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314.kt new file mode 100644 index 00000000000..e96d453f3ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314.kt @@ -0,0 +1,6 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun main() { + val x = run { ::run } // no error +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314.txt b/compiler/testData/diagnostics/tests/callableReference/kt34314.txt new file mode 100644 index 00000000000..a9fef69810f --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314.txt @@ -0,0 +1,3 @@ +package + +public fun main(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt new file mode 100644 index 00000000000..d0439f4a526 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun materialize(): T = TODO() + +fun main() { + val x = run { materialize() } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt new file mode 100644 index 00000000000..4f32d9431ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt @@ -0,0 +1,8 @@ +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun materialize(): T = TODO() + +fun main() { + val x = run { materialize() } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.txt b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.txt new file mode 100644 index 00000000000..feace21a8ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.txt @@ -0,0 +1,4 @@ +package + +public fun main(): kotlin.Unit +public fun materialize(): T diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 8142bb82411..8f5eafcbf65 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -1861,6 +1861,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/callableReference/kt32267.kt"); } + @TestMetadata("kt34314.kt") + public void testKt34314() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314.kt"); + } + + @TestMetadata("kt34314_lambda.kt") + public void testKt34314_lambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt"); + } + @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index c653c38ab7b..a0cdfbf5aa1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -1856,6 +1856,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/callableReference/kt32267.kt"); } + @TestMetadata("kt34314.kt") + public void testKt34314() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314.kt"); + } + + @TestMetadata("kt34314_lambda.kt") + public void testKt34314_lambda() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt"); + } + @TestMetadata("kt7430_wrongClassOnLHS.kt") public void testKt7430_wrongClassOnLHS() throws Exception { runTest("compiler/testData/diagnostics/tests/callableReference/kt7430_wrongClassOnLHS.kt");