[FIR JS] Support DYNAMIC_SUPERTYPE
This commit is contained in:
committed by
Space Team
parent
227969d787
commit
9e1c6f2f61
+6
@@ -2016,6 +2016,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.DYNAMIC_SUPERTYPE) { firDiagnostic ->
|
||||
DynamicSupertypeImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.DYNAMIC_UPPER_BOUND) { firDiagnostic ->
|
||||
DynamicUpperBoundImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
|
||||
+4
@@ -1431,6 +1431,10 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = MisplacedTypeParameterConstraints::class
|
||||
}
|
||||
|
||||
abstract class DynamicSupertype : KtFirDiagnostic<KtTypeReference>() {
|
||||
override val diagnosticClass get() = DynamicSupertype::class
|
||||
}
|
||||
|
||||
abstract class DynamicUpperBound : KtFirDiagnostic<KtTypeReference>() {
|
||||
override val diagnosticClass get() = DynamicUpperBound::class
|
||||
}
|
||||
|
||||
+5
@@ -1722,6 +1722,11 @@ internal class MisplacedTypeParameterConstraintsImpl(
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtFirDiagnostic.MisplacedTypeParameterConstraints(), KtAbstractFirDiagnostic<KtTypeParameter>
|
||||
|
||||
internal class DynamicSupertypeImpl(
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: KtLifetimeToken,
|
||||
) : KtFirDiagnostic.DynamicSupertype(), KtAbstractFirDiagnostic<KtTypeReference>
|
||||
|
||||
internal class DynamicUpperBoundImpl(
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: KtLifetimeToken,
|
||||
|
||||
+2
@@ -672,6 +672,8 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
|
||||
val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning<KtTypeParameter>()
|
||||
|
||||
val DYNAMIC_SUPERTYPE by error<KtTypeReference>()
|
||||
|
||||
val DYNAMIC_UPPER_BOUND by error<KtTypeReference>()
|
||||
|
||||
val DYNAMIC_RECEIVER_NOT_ALLOWED by error<KtElement>()
|
||||
|
||||
@@ -416,6 +416,7 @@ object FirErrors {
|
||||
val CYCLIC_GENERIC_UPPER_BOUND by error0<PsiElement>()
|
||||
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error0<KtDeclaration>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
|
||||
val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning0<KtTypeParameter>()
|
||||
val DYNAMIC_SUPERTYPE by error0<KtTypeReference>()
|
||||
val DYNAMIC_UPPER_BOUND by error0<KtTypeReference>()
|
||||
val DYNAMIC_RECEIVER_NOT_ALLOWED by error0<KtElement>()
|
||||
val INCOMPATIBLE_TYPES by error2<KtElement, ConeKotlinType, ConeKotlinType>()
|
||||
|
||||
+1
@@ -94,6 +94,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
FirTypeParametersInObjectChecker,
|
||||
FirSupertypesChecker,
|
||||
FirPrimaryConstructorSuperTypeChecker,
|
||||
FirDynamicSupertypeChecker,
|
||||
)
|
||||
|
||||
override val regularClassCheckers: Set<FirRegularClassChecker>
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 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.FirClass
|
||||
import org.jetbrains.kotlin.fir.types.ConeDynamicType
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
|
||||
object FirDynamicSupertypeChecker : FirClassChecker() {
|
||||
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
for (superType in declaration.superTypeRefs) {
|
||||
if (superType.coneType is ConeDynamicType) {
|
||||
reporter.reportOn(superType.source, FirErrors.DYNAMIC_SUPERTYPE, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -169,6 +169,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DIVISION_BY_ZERO
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DSL_SCOPE_VIOLATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DUPLICATE_LABEL_IN_WHEN
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DYNAMIC_RECEIVER_NOT_ALLOWED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DYNAMIC_SUPERTYPE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DYNAMIC_UPPER_BOUND
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ELSE_MISPLACED_IN_WHEN
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.EMPTY_CHARACTER_LITERAL
|
||||
@@ -1250,6 +1251,8 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
"If a type parameter has multiple constraints, they all need to be placed in the 'where' clause"
|
||||
)
|
||||
|
||||
map.put(DYNAMIC_SUPERTYPE, "A supertype cannot be dynamic")
|
||||
|
||||
map.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound")
|
||||
|
||||
map.put(DYNAMIC_RECEIVER_NOT_ALLOWED, "Dynamic receiver is prohibited")
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
interface Tr : dynamic
|
||||
interface Tr : <!DYNAMIC_SUPERTYPE!>dynamic<!>
|
||||
|
||||
fun <T: dynamic> foo() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user