[FIR] Mark implicit types in accessors as fake
To not check their types in deprecation checker
This commit is contained in:
committed by
teamcityserver
parent
caa6b630ab
commit
15be38192b
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.extended
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -21,7 +22,7 @@ object RedundantSetterParameterTypeChecker : FirPropertyChecker() {
|
||||
val propertyTypeSource = declaration.returnTypeRef.source
|
||||
val setterParameterTypeSource = valueParameter.returnTypeRef.source ?: return
|
||||
|
||||
if (setterParameterTypeSource != propertyTypeSource) {
|
||||
if (setterParameterTypeSource.kind !is FirFakeSourceElementKind && setterParameterTypeSource != propertyTypeSource) {
|
||||
reporter.reportOn(setterParameterTypeSource, REDUNDANT_SETTER_PARAMETER_TYPE, context)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.type
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirDeprecationChecker
|
||||
@@ -17,11 +18,11 @@ import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
|
||||
object FirDeprecatedTypeChecker : FirTypeRefChecker() {
|
||||
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (context.findClosest<FirPropertyAccessor>() != null) return
|
||||
|
||||
val source = typeRef.source ?: return
|
||||
if (source.kind is FirFakeSourceElementKind) return
|
||||
val resolved = typeRef.coneTypeSafe<ConeClassLikeType>() ?: return
|
||||
val symbol = resolved.lookupTag.toSymbol(context.session) ?: return
|
||||
|
||||
FirDeprecationChecker.reportDeprecationIfNeeded(typeRef.source, symbol, null, context, reporter)
|
||||
FirDeprecationChecker.reportDeprecationIfNeeded(source, symbol, null, context, reporter)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1233,10 +1233,11 @@ class DeclarationsConverter(
|
||||
var modifiers = Modifier()
|
||||
var isGetter = true
|
||||
var returnType: FirTypeRef? = null
|
||||
val propertyTypeRefToUse = propertyTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef)
|
||||
var firValueParameters: FirValueParameter = buildDefaultSetterValueParameter {
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = propertyTypeRef
|
||||
returnTypeRef = propertyTypeRefToUse
|
||||
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
||||
}
|
||||
var block: LighterASTNode? = null
|
||||
@@ -1248,7 +1249,7 @@ class DeclarationsConverter(
|
||||
SET_KEYWORD -> isGetter = false
|
||||
MODIFIER_LIST -> modifiers = convertModifierList(it)
|
||||
TYPE_REFERENCE -> returnType = convertType(it)
|
||||
VALUE_PARAMETER_LIST -> firValueParameters = convertSetterParameter(it, propertyTypeRef)
|
||||
VALUE_PARAMETER_LIST -> firValueParameters = convertSetterParameter(it, propertyTypeRefToUse)
|
||||
CONTRACT_EFFECT_LIST -> outerContractDescription = obtainContractDescription(it)
|
||||
BLOCK -> block = it
|
||||
else -> if (it.isExpression()) expression = it
|
||||
@@ -1272,7 +1273,7 @@ class DeclarationsConverter(
|
||||
sourceElement,
|
||||
baseModuleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
propertyTypeRef,
|
||||
propertyTypeRefToUse,
|
||||
accessorVisibility,
|
||||
isGetter
|
||||
)
|
||||
@@ -1287,7 +1288,7 @@ class DeclarationsConverter(
|
||||
source = sourceElement
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = returnType ?: if (isGetter) propertyTypeRef else implicitUnitType
|
||||
returnTypeRef = returnType ?: if (isGetter) propertyTypeRefToUse else implicitUnitType
|
||||
symbol = FirPropertyAccessorSymbol()
|
||||
this.isGetter = isGetter
|
||||
this.status = status
|
||||
|
||||
@@ -368,6 +368,7 @@ open class RawFirBuilder(
|
||||
isExternal = property.hasModifier(EXTERNAL_KEYWORD) ||
|
||||
this@toFirPropertyAccessor?.hasModifier(EXTERNAL_KEYWORD) == true
|
||||
}
|
||||
val propertyTypeRefToUse = propertyTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef)
|
||||
return when {
|
||||
this != null && hasBody() -> {
|
||||
// Property has a non-default getter or setter.
|
||||
@@ -379,7 +380,7 @@ open class RawFirBuilder(
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = if (isGetter) {
|
||||
returnTypeReference?.convertSafe() ?: propertyTypeRef
|
||||
returnTypeReference?.convertSafe() ?: propertyTypeRefToUse
|
||||
} else {
|
||||
returnTypeReference.toFirOrUnitType()
|
||||
}
|
||||
@@ -387,13 +388,13 @@ open class RawFirBuilder(
|
||||
this.status = status
|
||||
extractAnnotationsTo(this)
|
||||
this@RawFirBuilder.context.firFunctionTargets += accessorTarget
|
||||
extractValueParametersTo(this, propertyTypeRef)
|
||||
extractValueParametersTo(this, propertyTypeRefToUse)
|
||||
if (!isGetter && valueParameters.isEmpty()) {
|
||||
valueParameters += buildDefaultSetterValueParameter {
|
||||
this.source = source.fakeElement(FirFakeSourceElementKind.DefaultAccessor)
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = propertyTypeRef
|
||||
returnTypeRef = propertyTypeRefToUse
|
||||
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
||||
}
|
||||
}
|
||||
@@ -420,7 +421,7 @@ open class RawFirBuilder(
|
||||
propertySource,
|
||||
baseModuleData,
|
||||
FirDeclarationOrigin.Source,
|
||||
propertyTypeRef,
|
||||
propertyTypeRefToUse,
|
||||
accessorVisibility,
|
||||
isGetter
|
||||
)
|
||||
|
||||
@@ -24,8 +24,8 @@ class Properties {
|
||||
var y : <!DEPRECATION!>Obsolete<!> = <!DEPRECATION!>Obsolete<!>()
|
||||
|
||||
var n : <!DEPRECATION!>Obsolete<!>
|
||||
get() = <!DEPRECATION!>Obsolete<!>()
|
||||
set(value) {}
|
||||
get() = <!DEPRECATION!>Obsolete<!>()
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
fun param(param: <!DEPRECATION!>Obsolete<!>) { param.use() }
|
||||
|
||||
Vendored
-14
@@ -1,14 +0,0 @@
|
||||
// !JVM_TARGET: 1.8
|
||||
// !JVM_DEFAULT_MODE: enable
|
||||
|
||||
interface B {
|
||||
|
||||
@<!DEPRECATION!>JvmDefault<!>
|
||||
val prop1: String
|
||||
<!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> get() = ""
|
||||
|
||||
|
||||
var prop2: String
|
||||
<!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> get() = ""
|
||||
<!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> set(value) {}
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !JVM_TARGET: 1.8
|
||||
// !JVM_DEFAULT_MODE: enable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user