Transform VisibilityError diagnostic for callable references to further report it on the corresponding argument of a base call
^KT-46437 Fixed
This commit is contained in:
+6
@@ -2747,6 +2747,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46437.kt")
|
||||
public void testKt46437() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt46437.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt49038.kt")
|
||||
public void testKt49038() throws Exception {
|
||||
|
||||
+6
@@ -2747,6 +2747,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46437.kt")
|
||||
public void testKt46437() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt46437.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt49038.kt")
|
||||
public void testKt49038() throws Exception {
|
||||
|
||||
+6
@@ -2747,6 +2747,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46437.kt")
|
||||
public void testKt46437() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt46437.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt49038.kt")
|
||||
public void testKt49038() throws Exception {
|
||||
|
||||
+12
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.*
|
||||
import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isNull
|
||||
import org.jetbrains.kotlin.psi.psiUtil.lastBlockStatementOrThis
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.util.*
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
@@ -24,6 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.calls.util.*
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstantChecker
|
||||
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
@@ -142,6 +144,16 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
SmartCastDiagnostic::class.java -> reportSmartCast(diagnostic as SmartCastDiagnostic)
|
||||
UnstableSmartCastDiagnosticError::class.java,
|
||||
UnstableSmartCastResolutionError::class.java -> reportUnstableSmartCast(diagnostic as UnstableSmartCast)
|
||||
VisibilityErrorOnArgument::class.java -> {
|
||||
diagnostic as VisibilityErrorOnArgument
|
||||
val invisibleMember = diagnostic.invisibleMember
|
||||
val argumentExpression =
|
||||
diagnostic.argument.psiCallArgument.valueArgument.getArgumentExpression()?.lastBlockStatementOrThis()
|
||||
|
||||
if (argumentExpression != null) {
|
||||
trace.report(INVISIBLE_MEMBER.on(argumentExpression, invisibleMember, invisibleMember.visibility, invisibleMember))
|
||||
}
|
||||
}
|
||||
TooManyArguments::class.java -> {
|
||||
trace.reportTrailingLambdaErrorOr(callArgument.psiExpression) { expr ->
|
||||
TOO_MANY_ARGUMENTS.on(expr, (diagnostic as TooManyArguments).descriptor)
|
||||
|
||||
+3
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.resolve.calls.components
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityErrorOnArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isInapplicable
|
||||
|
||||
class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictResolver: CallableReferenceOverloadConflictResolver) {
|
||||
@@ -43,6 +45,7 @@ class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictRes
|
||||
chosenCandidate.diagnostics.forEach {
|
||||
val transformedDiagnostic = when (it) {
|
||||
is CompatibilityWarning -> CompatibilityWarningOnArgument(argument, it.candidate)
|
||||
is VisibilityError -> VisibilityErrorOnArgument(argument, it.invisibleMember)
|
||||
else -> it
|
||||
}
|
||||
diagnosticsHolder.addDiagnostic(transformedDiagnostic)
|
||||
|
||||
+10
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
@@ -111,6 +112,15 @@ class VisibilityError(val invisibleMember: DeclarationDescriptorWithVisibility)
|
||||
}
|
||||
}
|
||||
|
||||
class VisibilityErrorOnArgument(
|
||||
val argument: KotlinCallArgument,
|
||||
val invisibleMember: DeclarationDescriptorWithVisibility
|
||||
) : ResolutionDiagnostic(RUNTIME_ERROR) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCallArgument(argument, this)
|
||||
}
|
||||
}
|
||||
|
||||
class NestedClassViaInstanceReference(val classDescriptor: ClassDescriptor) : ResolutionDiagnostic(IMPOSSIBLE_TO_GENERATE)
|
||||
class InnerClassViaStaticReference(val classDescriptor: ClassDescriptor) : ResolutionDiagnostic(IMPOSSIBLE_TO_GENERATE)
|
||||
class UnsupportedInnerClassCall(val message: String) : ResolutionDiagnostic(IMPOSSIBLE_TO_GENERATE)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
if (true) X::<!UNRESOLVED_REFERENCE!>y<!> else null
|
||||
return "OK"
|
||||
}
|
||||
|
||||
object X {
|
||||
private val y = null
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
if (true) <!INVISIBLE_MEMBER!>X::y<!> else null
|
||||
return "OK"
|
||||
}
|
||||
|
||||
object X {
|
||||
private val y = null
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.String
|
||||
|
||||
public object X {
|
||||
private constructor X()
|
||||
private final val y: kotlin.Nothing? = null
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+6
@@ -2753,6 +2753,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt37530.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt46437.kt")
|
||||
public void testKt46437() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/kt46437.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt49038.kt")
|
||||
public void testKt49038() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user