[FIR] Report UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL
^KT-59969 Fixed
This commit is contained in:
committed by
Space Team
parent
906c27736f
commit
7151e6a41c
-37
@@ -1,37 +0,0 @@
|
|||||||
interface Context1
|
|
||||||
|
|
||||||
interface Context2<A> {
|
|
||||||
fun getContextElement(): A
|
|
||||||
}
|
|
||||||
|
|
||||||
class Context2Impl<A>(value: A) : Context2<A> {
|
|
||||||
override fun getContextElement(): A
|
|
||||||
|
|
||||||
val value: A
|
|
||||||
}
|
|
||||||
|
|
||||||
context(Int, String)
|
|
||||||
class A {
|
|
||||||
constructor(int: Int)
|
|
||||||
}
|
|
||||||
|
|
||||||
context(Context1, c2@Context2<String>)
|
|
||||||
class B {
|
|
||||||
override fun toString(): String
|
|
||||||
}
|
|
||||||
|
|
||||||
context(Context2<A>)
|
|
||||||
class C<A> {
|
|
||||||
val a: A
|
|
||||||
get()
|
|
||||||
}
|
|
||||||
|
|
||||||
context(Context1)
|
|
||||||
@Deprecated(message = "Use `B` instead.")
|
|
||||||
class D
|
|
||||||
|
|
||||||
context(b@B, `fun`@A)
|
|
||||||
fun foo()
|
|
||||||
|
|
||||||
context(Context2<C<String>>)
|
|
||||||
fun bar(): ERROR
|
|
||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// !LANGUAGE: +ContextReceivers
|
||||||
|
|
||||||
interface Context1
|
interface Context1
|
||||||
|
|
||||||
interface Context2<A> {
|
interface Context2<A> {
|
||||||
|
|||||||
compiler/fir/analysis-tests/testData/resolve/expresssions/propertyAccessWithExplicitTypeArguments.kt
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// ISSUE: KT-54978
|
// ISSUE: KT-54978
|
||||||
|
// !LANGUAGE: +ContextReceivers
|
||||||
|
|
||||||
// Case 1: Parameters and local variables
|
// Case 1: Parameters and local variables
|
||||||
fun f1(x: Int) {
|
fun f1(x: Int) {
|
||||||
|
|||||||
+1
-1
@@ -627,7 +627,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
|||||||
parameter<ConeKotlinType>("contextReceiverRepresentation")
|
parameter<ConeKotlinType>("contextReceiverRepresentation")
|
||||||
}
|
}
|
||||||
val AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER by error<KtElement>(PositioningStrategy.REFERENCE_BY_QUALIFIED)
|
val AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER by error<KtElement>(PositioningStrategy.REFERENCE_BY_QUALIFIED)
|
||||||
val UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL by error<KtElement>()
|
val UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL by error<KtElement>(PositioningStrategy.NAME_IDENTIFIER)
|
||||||
}
|
}
|
||||||
|
|
||||||
val TYPES_AND_TYPE_PARAMETERS by object : DiagnosticGroup("Types & type parameters") {
|
val TYPES_AND_TYPE_PARAMETERS by object : DiagnosticGroup("Types & type parameters") {
|
||||||
|
|||||||
+1
-1
@@ -397,7 +397,7 @@ object FirErrors {
|
|||||||
val NO_CONTEXT_RECEIVER by error1<KtElement, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
val NO_CONTEXT_RECEIVER by error1<KtElement, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||||
val MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER by error1<KtElement, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
val MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER by error1<KtElement, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||||
val AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER by error0<KtElement>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
val AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER by error0<KtElement>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||||
val UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL by error0<KtElement>()
|
val UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL by error0<KtElement>(SourceElementPositioningStrategies.NAME_IDENTIFIER)
|
||||||
|
|
||||||
// Types & type parameters
|
// Types & type parameters
|
||||||
val RECURSION_IN_IMPLICIT_TYPES by error0<PsiElement>()
|
val RECURSION_IN_IMPLICIT_TYPES by error0<PsiElement>()
|
||||||
|
|||||||
+2
@@ -268,6 +268,8 @@ private fun mapInapplicableCandidateError(
|
|||||||
rootCause.expectedContextReceiverType.removeTypeVariableTypes(typeContext)
|
rootCause.expectedContextReceiverType.removeTypeVariableTypes(typeContext)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
is UnsupportedContextualDeclarationCall -> FirErrors.UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL.createOn(source)
|
||||||
|
|
||||||
is AmbiguousValuesForContextReceiverParameter ->
|
is AmbiguousValuesForContextReceiverParameter ->
|
||||||
FirErrors.MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER.createOn(
|
FirErrors.MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER.createOn(
|
||||||
qualifiedAccessSource ?: source,
|
qualifiedAccessSource ?: source,
|
||||||
|
|||||||
@@ -202,6 +202,11 @@ object CheckContextReceivers : ResolutionStage() {
|
|||||||
candidate.substitutor.substituteOrSelf(it.typeRef.coneType)
|
candidate.substitutor.substituteOrSelf(it.typeRef.coneType)
|
||||||
}?.takeUnless { it.isEmpty() } ?: return
|
}?.takeUnless { it.isEmpty() } ?: return
|
||||||
|
|
||||||
|
if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) {
|
||||||
|
sink.reportDiagnostic(UnsupportedContextualDeclarationCall)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val receiverGroups: List<List<FirExpression>> =
|
val receiverGroups: List<List<FirExpression>> =
|
||||||
context.bodyResolveContext.towerDataContext.towerDataElements.asReversed().mapNotNull { towerDataElement ->
|
context.bodyResolveContext.towerDataContext.towerDataElements.asReversed().mapNotNull { towerDataElement ->
|
||||||
towerDataElement.implicitReceiver?.receiverExpression?.let(::listOf)
|
towerDataElement.implicitReceiver?.receiverExpression?.let(::listOf)
|
||||||
|
|||||||
+2
@@ -137,6 +137,8 @@ class NoApplicableValueForContextReceiver(
|
|||||||
val expectedContextReceiverType: ConeKotlinType
|
val expectedContextReceiverType: ConeKotlinType
|
||||||
) : ResolutionDiagnostic(INAPPLICABLE)
|
) : ResolutionDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
|
object UnsupportedContextualDeclarationCall : ResolutionDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
class AmbiguousValuesForContextReceiverParameter(
|
class AmbiguousValuesForContextReceiverParameter(
|
||||||
val expectedContextReceiverType: ConeKotlinType,
|
val expectedContextReceiverType: ConeKotlinType,
|
||||||
) : ResolutionDiagnostic(INAPPLICABLE)
|
) : ResolutionDiagnostic(INAPPLICABLE)
|
||||||
|
|||||||
+5
-5
@@ -29,11 +29,11 @@ fun useWithContextReceivers() {
|
|||||||
with(42) {
|
with(42) {
|
||||||
with("") {
|
with("") {
|
||||||
f({}, 42)
|
f({}, 42)
|
||||||
sameAsFWithoutNonContextualCounterpart({}, 42)
|
<!UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL!>sameAsFWithoutNonContextualCounterpart<!>({}, 42)
|
||||||
p
|
<!UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL!>p<!>
|
||||||
val a = A()
|
val a = <!UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL!>A<!>()
|
||||||
a.p
|
a.<!UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL!>p<!>
|
||||||
a.m()
|
a.<!UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL!>m<!>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user