K1: add diagnostic BUILDER_INFERENCE_STUB_RECEIVER

It's reported on receivers in extension function calls with stub type,
as such calls can shadow members of finalized stub types causing
change of resolve when corresponding type argument specified explicitly

It works by checking extension receiver during call resolution parts run
That way we can easily detect if we found an extension applicable to
stub receiver and report call diagnostic for it

KT-53739
This commit is contained in:
Simon Ogorodnik
2022-08-26 16:23:01 +02:00
committed by teamcity
parent 105358dcf6
commit 154e53c701
18 changed files with 428 additions and 44 deletions
@@ -661,9 +661,25 @@ internal object CheckReceivers : ResolutionPart() {
candidateDescriptor.dispatchReceiverParameter,
shouldCheckImplicitInvoke = true,
)
1 -> {
if (resolvedCall.extensionReceiverArgument == null) {
resolvedCall.extensionReceiverArgument = chooseExtensionReceiverCandidate() ?: return
val checkBuilderInferenceRestriction =
!callComponents.languageVersionSettings
.supportsFeature(LanguageFeature.NoBuilderInferenceWithoutAnnotationRestriction)
if (checkBuilderInferenceRestriction) {
var extensionReceiverArgument = resolvedCall.extensionReceiverArgument
if (extensionReceiverArgument == null) {
extensionReceiverArgument = chooseExtensionReceiverCandidate() ?: return
resolvedCall.extensionReceiverArgument = extensionReceiverArgument
}
if (extensionReceiverArgument.receiver.receiverValue.type is StubTypeForBuilderInference) {
addDiagnostic(
StubBuilderInferenceReceiver(
extensionReceiverArgument,
candidateDescriptor.extensionReceiverParameter!!
)
)
}
}
checkReceiver(
resolvedCall.extensionReceiverArgument,
@@ -73,6 +73,13 @@ class MultiLambdaBuilderInferenceRestriction(
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
}
class StubBuilderInferenceReceiver(
val receiver: SimpleKotlinCallArgument,
val extensionReceiverParameter: ReceiverParameterDescriptor,
) : KotlinCallDiagnostic(RESOLVED) {
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
}
class MixingNamedAndPositionArguments(override val argument: KotlinCallArgument) : InapplicableArgumentDiagnostic()
class NamedArgumentNotAllowed(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) {