[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
|
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.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
|
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirPropertyChecker
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||||
@@ -21,7 +22,7 @@ object RedundantSetterParameterTypeChecker : FirPropertyChecker() {
|
|||||||
val propertyTypeSource = declaration.returnTypeRef.source
|
val propertyTypeSource = declaration.returnTypeRef.source
|
||||||
val setterParameterTypeSource = valueParameter.returnTypeRef.source ?: return
|
val setterParameterTypeSource = valueParameter.returnTypeRef.source ?: return
|
||||||
|
|
||||||
if (setterParameterTypeSource != propertyTypeSource) {
|
if (setterParameterTypeSource.kind !is FirFakeSourceElementKind && setterParameterTypeSource != propertyTypeSource) {
|
||||||
reporter.reportOn(setterParameterTypeSource, REDUNDANT_SETTER_PARAMETER_TYPE, context)
|
reporter.reportOn(setterParameterTypeSource, REDUNDANT_SETTER_PARAMETER_TYPE, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.checkers.type
|
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.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirDeprecationChecker
|
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirDeprecationChecker
|
||||||
@@ -17,11 +18,11 @@ import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
|||||||
|
|
||||||
object FirDeprecatedTypeChecker : FirTypeRefChecker() {
|
object FirDeprecatedTypeChecker : FirTypeRefChecker() {
|
||||||
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
|
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 resolved = typeRef.coneTypeSafe<ConeClassLikeType>() ?: return
|
||||||
val symbol = resolved.lookupTag.toSymbol(context.session) ?: 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 modifiers = Modifier()
|
||||||
var isGetter = true
|
var isGetter = true
|
||||||
var returnType: FirTypeRef? = null
|
var returnType: FirTypeRef? = null
|
||||||
|
val propertyTypeRefToUse = propertyTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef)
|
||||||
var firValueParameters: FirValueParameter = buildDefaultSetterValueParameter {
|
var firValueParameters: FirValueParameter = buildDefaultSetterValueParameter {
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = propertyTypeRef
|
returnTypeRef = propertyTypeRefToUse
|
||||||
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
||||||
}
|
}
|
||||||
var block: LighterASTNode? = null
|
var block: LighterASTNode? = null
|
||||||
@@ -1248,7 +1249,7 @@ class DeclarationsConverter(
|
|||||||
SET_KEYWORD -> isGetter = false
|
SET_KEYWORD -> isGetter = false
|
||||||
MODIFIER_LIST -> modifiers = convertModifierList(it)
|
MODIFIER_LIST -> modifiers = convertModifierList(it)
|
||||||
TYPE_REFERENCE -> returnType = convertType(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)
|
CONTRACT_EFFECT_LIST -> outerContractDescription = obtainContractDescription(it)
|
||||||
BLOCK -> block = it
|
BLOCK -> block = it
|
||||||
else -> if (it.isExpression()) expression = it
|
else -> if (it.isExpression()) expression = it
|
||||||
@@ -1272,7 +1273,7 @@ class DeclarationsConverter(
|
|||||||
sourceElement,
|
sourceElement,
|
||||||
baseModuleData,
|
baseModuleData,
|
||||||
FirDeclarationOrigin.Source,
|
FirDeclarationOrigin.Source,
|
||||||
propertyTypeRef,
|
propertyTypeRefToUse,
|
||||||
accessorVisibility,
|
accessorVisibility,
|
||||||
isGetter
|
isGetter
|
||||||
)
|
)
|
||||||
@@ -1287,7 +1288,7 @@ class DeclarationsConverter(
|
|||||||
source = sourceElement
|
source = sourceElement
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = returnType ?: if (isGetter) propertyTypeRef else implicitUnitType
|
returnTypeRef = returnType ?: if (isGetter) propertyTypeRefToUse else implicitUnitType
|
||||||
symbol = FirPropertyAccessorSymbol()
|
symbol = FirPropertyAccessorSymbol()
|
||||||
this.isGetter = isGetter
|
this.isGetter = isGetter
|
||||||
this.status = status
|
this.status = status
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ open class RawFirBuilder(
|
|||||||
isExternal = property.hasModifier(EXTERNAL_KEYWORD) ||
|
isExternal = property.hasModifier(EXTERNAL_KEYWORD) ||
|
||||||
this@toFirPropertyAccessor?.hasModifier(EXTERNAL_KEYWORD) == true
|
this@toFirPropertyAccessor?.hasModifier(EXTERNAL_KEYWORD) == true
|
||||||
}
|
}
|
||||||
|
val propertyTypeRefToUse = propertyTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef)
|
||||||
return when {
|
return when {
|
||||||
this != null && hasBody() -> {
|
this != null && hasBody() -> {
|
||||||
// Property has a non-default getter or setter.
|
// Property has a non-default getter or setter.
|
||||||
@@ -379,7 +380,7 @@ open class RawFirBuilder(
|
|||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = if (isGetter) {
|
returnTypeRef = if (isGetter) {
|
||||||
returnTypeReference?.convertSafe() ?: propertyTypeRef
|
returnTypeReference?.convertSafe() ?: propertyTypeRefToUse
|
||||||
} else {
|
} else {
|
||||||
returnTypeReference.toFirOrUnitType()
|
returnTypeReference.toFirOrUnitType()
|
||||||
}
|
}
|
||||||
@@ -387,13 +388,13 @@ open class RawFirBuilder(
|
|||||||
this.status = status
|
this.status = status
|
||||||
extractAnnotationsTo(this)
|
extractAnnotationsTo(this)
|
||||||
this@RawFirBuilder.context.firFunctionTargets += accessorTarget
|
this@RawFirBuilder.context.firFunctionTargets += accessorTarget
|
||||||
extractValueParametersTo(this, propertyTypeRef)
|
extractValueParametersTo(this, propertyTypeRefToUse)
|
||||||
if (!isGetter && valueParameters.isEmpty()) {
|
if (!isGetter && valueParameters.isEmpty()) {
|
||||||
valueParameters += buildDefaultSetterValueParameter {
|
valueParameters += buildDefaultSetterValueParameter {
|
||||||
this.source = source.fakeElement(FirFakeSourceElementKind.DefaultAccessor)
|
this.source = source.fakeElement(FirFakeSourceElementKind.DefaultAccessor)
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
origin = FirDeclarationOrigin.Source
|
origin = FirDeclarationOrigin.Source
|
||||||
returnTypeRef = propertyTypeRef
|
returnTypeRef = propertyTypeRefToUse
|
||||||
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
symbol = FirValueParameterSymbol(NAME_FOR_DEFAULT_VALUE_PARAMETER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,7 +421,7 @@ open class RawFirBuilder(
|
|||||||
propertySource,
|
propertySource,
|
||||||
baseModuleData,
|
baseModuleData,
|
||||||
FirDeclarationOrigin.Source,
|
FirDeclarationOrigin.Source,
|
||||||
propertyTypeRef,
|
propertyTypeRefToUse,
|
||||||
accessorVisibility,
|
accessorVisibility,
|
||||||
isGetter
|
isGetter
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ class Properties {
|
|||||||
var y : <!DEPRECATION!>Obsolete<!> = <!DEPRECATION!>Obsolete<!>()
|
var y : <!DEPRECATION!>Obsolete<!> = <!DEPRECATION!>Obsolete<!>()
|
||||||
|
|
||||||
var n : <!DEPRECATION!>Obsolete<!>
|
var n : <!DEPRECATION!>Obsolete<!>
|
||||||
get() = <!DEPRECATION!>Obsolete<!>()
|
get() = <!DEPRECATION!>Obsolete<!>()
|
||||||
set(value) {}
|
set(value) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun param(param: <!DEPRECATION!>Obsolete<!>) { param.use() }
|
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_TARGET: 1.8
|
||||||
// !JVM_DEFAULT_MODE: enable
|
// !JVM_DEFAULT_MODE: enable
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user