[K2] Disappeared UNSUPPORTED
Prohibit DelegationBy specifier when no primary constructor ^KT-59881
This commit is contained in:
committed by
Space Team
parent
23bed574c1
commit
c569fc170b
+27
@@ -20,6 +20,9 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirField
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInterface
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
@@ -102,6 +105,7 @@ object FirSupertypesChecker : FirClassChecker() {
|
||||
}
|
||||
|
||||
checkDelegationNotToInterface(declaration, context, reporter)
|
||||
checkDelegationWithoutPrimaryConstructor(declaration, context, reporter)
|
||||
|
||||
if (declaration is FirRegularClass && declaration.superTypeRefs.size > 1) {
|
||||
checkInconsistentTypeParameters(listOf(Pair(null, declaration.symbol)), context, reporter, declaration.source, true)
|
||||
@@ -219,4 +223,27 @@ object FirSupertypesChecker : FirClassChecker() {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
private fun checkDelegationWithoutPrimaryConstructor(
|
||||
declaration: FirClass,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter,
|
||||
) {
|
||||
if (declaration.isInterface) return
|
||||
if (declaration.isExpect) return
|
||||
val primaryConstructor = declaration.primaryConstructorIfAny(context.session)
|
||||
if (primaryConstructor != null) return
|
||||
for (subDeclaration in declaration.declarations) {
|
||||
if (subDeclaration !is FirField) continue
|
||||
if (subDeclaration.visibility == Visibilities.Private && subDeclaration.name.isDelegated) {
|
||||
reporter.reportOn(
|
||||
subDeclaration.source,
|
||||
FirErrors.UNSUPPORTED,
|
||||
"Delegation without primary constructor is not supported",
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
interface A
|
||||
class AImpl : A
|
||||
|
||||
class B : A by AImpl() {
|
||||
constructor()
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// FIR_IDENTICAL
|
||||
interface A
|
||||
class AImpl : A
|
||||
|
||||
class B : <!UNSUPPORTED!>A by AImpl()<!> {
|
||||
constructor()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user