[K2] Disappeared UNSUPPORTED_FEATURE (2)
Added a check for the enabled context receivers feature flag for declaration. ^KT-59913
This commit is contained in:
committed by
Space Team
parent
685c8e4fe7
commit
c04767f1f4
+1
@@ -37,6 +37,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
FirExpectConsistencyChecker,
|
||||
FirOptionalExpectationDeclarationChecker,
|
||||
FirMissingDependencySupertypeChecker.ForDeclarations,
|
||||
FirContextReceiversDeclarationChecker,
|
||||
)
|
||||
|
||||
override val classLikeCheckers: Set<FirClassLikeChecker>
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import com.intellij.lang.LighterASTNode
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtLightSourceElement
|
||||
import org.jetbrains.kotlin.KtNodeTypes.CONTEXT_RECEIVER_LIST
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.toKtLightSourceElement
|
||||
import org.jetbrains.kotlin.util.getChildren
|
||||
|
||||
object FirContextReceiversDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) return
|
||||
if (declaration.source?.kind is KtFakeSourceElementKind) return
|
||||
if (!declaration.hasContextReceiver()) return
|
||||
val source = declaration.source?.findContextReceiverListSource() ?: return
|
||||
|
||||
reporter.reportOn(
|
||||
source,
|
||||
FirErrors.UNSUPPORTED_FEATURE,
|
||||
LanguageFeature.ContextReceivers to context.languageVersionSettings,
|
||||
context
|
||||
)
|
||||
}
|
||||
|
||||
private fun FirDeclaration.hasContextReceiver(): Boolean {
|
||||
val contextReceivers = when (this) {
|
||||
is FirCallableDeclaration -> contextReceivers
|
||||
is FirRegularClass -> contextReceivers
|
||||
is FirScript -> contextReceivers
|
||||
else -> emptyList()
|
||||
}
|
||||
return contextReceivers.isNotEmpty()
|
||||
}
|
||||
|
||||
|
||||
private fun KtSourceElement.findContextReceiverListSource(): KtLightSourceElement? {
|
||||
var contextReceiverList: LighterASTNode? = null
|
||||
var contextReceiverListOffset = startOffset
|
||||
|
||||
val nodes = lighterASTNode.getChildren(treeStructure)
|
||||
for (node in nodes) {
|
||||
if (node.tokenType == CONTEXT_RECEIVER_LIST) {
|
||||
contextReceiverList = node
|
||||
break
|
||||
} else {
|
||||
contextReceiverListOffset += node.endOffset - node.startOffset
|
||||
}
|
||||
}
|
||||
if (contextReceiverList == null) return null
|
||||
|
||||
return contextReceiverList.toKtLightSourceElement(
|
||||
treeStructure,
|
||||
startOffset = contextReceiverListOffset,
|
||||
endOffset = contextReceiverListOffset + contextReceiverList.textLength,
|
||||
)
|
||||
}
|
||||
}
|
||||
Vendored
+2
-2
@@ -3,11 +3,11 @@ fun List<Int>.f() {
|
||||
this@List.size
|
||||
}
|
||||
|
||||
context(String)
|
||||
<!UNSUPPORTED_FEATURE!>context(String)<!>
|
||||
fun Int.f() {
|
||||
this@String.length
|
||||
this@Int.toDouble()
|
||||
}
|
||||
|
||||
context(String)
|
||||
<!UNSUPPORTED_FEATURE!>context(String)<!>
|
||||
val p: String get() = this@String
|
||||
|
||||
+12
-6
@@ -1,6 +1,6 @@
|
||||
// !DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
context(Any)
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!>
|
||||
fun f(g: <!UNSUPPORTED_FEATURE!>context(Any) () -> Unit<!>, value: Any): <!UNSUPPORTED_FEATURE!>context(A) () -> Unit<!> {
|
||||
return value as <!UNSUPPORTED_FEATURE!>(context(A) () -> Unit)<!>
|
||||
}
|
||||
@@ -9,19 +9,25 @@ fun f(g: () -> Unit, value: Any) : () -> Unit {
|
||||
return g
|
||||
}
|
||||
|
||||
context(Any)
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!>
|
||||
fun sameAsFWithoutNonContextualCounterpart(g: () -> Unit, value: Any) : () -> Unit {
|
||||
return g
|
||||
}
|
||||
|
||||
context(Any) val p get() = 42
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!> val p get() = 42
|
||||
|
||||
context(String, Int)
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class D constructor(){}
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class C(){}
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class A {
|
||||
context(Any)
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!>
|
||||
val p: Any get() = 42
|
||||
|
||||
context(String, Int)
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
fun m() {}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -16,6 +16,12 @@ fun sameAsFWithoutNonContextualCounterpart(g: () -> Unit, value: Any) : () -> Un
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!> val p get() = 42
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class D constructor(){}
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class C(){}
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>context(String, Int)<!>
|
||||
class A {
|
||||
<!UNSUPPORTED_FEATURE!>context(Any)<!>
|
||||
|
||||
+15
@@ -14,3 +14,18 @@ context(kotlin.String, kotlin.Int) public final class A {
|
||||
context(kotlin.String, kotlin.Int) public final fun m(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
context(kotlin.String, kotlin.Int) public final class C {
|
||||
public constructor C()
|
||||
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
|
||||
}
|
||||
|
||||
context(kotlin.String, kotlin.Int) public final class D {
|
||||
public constructor D()
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -2,6 +2,8 @@
|
||||
context(O) val INSTANCE: O? defined in O
|
||||
val INSTANCE: O defined in O
|
||||
|
||||
/kt59590WithContextReceiver.fir.kt:5:5: error: The feature "context receivers" is experimental and should be enabled explicitly
|
||||
|
||||
/kt59590WithContextReceiver.fir.kt:5:5: error: Platform declaration clash: The following declarations have the same JVM signature (INSTANCELO;):
|
||||
context(O) val INSTANCE: O? defined in O
|
||||
val INSTANCE: O defined in O
|
||||
|
||||
compiler/testData/diagnostics/testsWithJvmBackend/contextReceivers/kt59590WithContextReceiver.fir.kt
Vendored
+2
-2
@@ -2,7 +2,7 @@
|
||||
// !RENDER_ALL_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>object O {
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>context(O)
|
||||
<!CONFLICTING_JVM_DECLARATIONS!><!UNSUPPORTED_FEATURE!>context(O)<!>
|
||||
@JvmField
|
||||
val INSTANCE: O? = null<!>
|
||||
}<!>
|
||||
}<!>
|
||||
|
||||
Reference in New Issue
Block a user