K1:report warning on OptIn usages inside SAM constructor #KT-47708 Fixed
This commit is contained in:
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
|||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationSettings
|
import org.jetbrains.kotlin.resolve.deprecation.DeprecationSettings
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
|
import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import org.jetbrains.kotlin.types.AbbreviatedType
|
import org.jetbrains.kotlin.types.AbbreviatedType
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
@@ -97,6 +98,15 @@ class OptInUsageChecker(project: Project) : CallChecker {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (resultingDescriptor is SamConstructorDescriptor) {
|
||||||
|
// KT-47708 special case (warning only)
|
||||||
|
val methodDescriptor = resultingDescriptor.getSingleAbstractMethod()
|
||||||
|
val samOptIns = methodDescriptor.loadOptIns(moduleAnnotationsResolver, context.languageVersionSettings)
|
||||||
|
.map { (fqName, _, message) ->
|
||||||
|
OptInDescription(fqName, OptInDescription.Severity.WARNING, message)
|
||||||
|
}
|
||||||
|
reportNotAllowedOptIns(samOptIns, reportOn, context)
|
||||||
|
}
|
||||||
reportNotAllowedOptIns(optIns, reportOn, context)
|
reportNotAllowedOptIns(optIns, reportOn, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ fun regressionTestOverrides() {
|
|||||||
val anonymous: StableInterface = object : StableInterface {
|
val anonymous: StableInterface = object : StableInterface {
|
||||||
override fun <!OPT_IN_OVERRIDE_ERROR!>experimentalMethod<!>() {} // correctly fails check
|
override fun <!OPT_IN_OVERRIDE_ERROR!>experimentalMethod<!>() {} // correctly fails check
|
||||||
}
|
}
|
||||||
val lambda = StableInterface {} // this does not get flagged
|
val lambda = <!OPT_IN_USAGE!>StableInterface<!> {} // this does not get flagged
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExperimentalKotlinAnnotation
|
@ExperimentalKotlinAnnotation
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.synthetic.FunctionInterfaceConstructorDescriptor
|
import org.jetbrains.kotlin.descriptors.synthetic.FunctionInterfaceConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||||
|
|
||||||
interface SamConstructorDescriptor : SimpleFunctionDescriptor, FunctionInterfaceConstructorDescriptor
|
interface SamConstructorDescriptor : SimpleFunctionDescriptor, FunctionInterfaceConstructorDescriptor {
|
||||||
|
fun getSingleAbstractMethod(): CallableMemberDescriptor
|
||||||
|
}
|
||||||
|
|
||||||
class SamConstructorDescriptorImpl(
|
class SamConstructorDescriptorImpl(
|
||||||
containingDeclaration: DeclarationDescriptor,
|
containingDeclaration: DeclarationDescriptor,
|
||||||
@@ -28,6 +30,9 @@ class SamConstructorDescriptorImpl(
|
|||||||
), SamConstructorDescriptor {
|
), SamConstructorDescriptor {
|
||||||
override val baseDescriptorForSynthetic: ClassDescriptor
|
override val baseDescriptorForSynthetic: ClassDescriptor
|
||||||
get() = samInterface
|
get() = samInterface
|
||||||
|
|
||||||
|
override fun getSingleAbstractMethod(): CallableMemberDescriptor =
|
||||||
|
getAbstractMembers(samInterface).single()
|
||||||
}
|
}
|
||||||
|
|
||||||
object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
||||||
|
|||||||
+3
@@ -27,6 +27,9 @@ class SamTypeAliasConstructorDescriptorImpl(
|
|||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
typeAliasDescriptor.source
|
typeAliasDescriptor.source
|
||||||
), SamTypeAliasConstructorDescriptor {
|
), SamTypeAliasConstructorDescriptor {
|
||||||
|
override fun getSingleAbstractMethod(): CallableMemberDescriptor =
|
||||||
|
expandedConstructorDescriptor.getSingleAbstractMethod()
|
||||||
|
|
||||||
override val baseDescriptorForSynthetic: ClassDescriptor
|
override val baseDescriptorForSynthetic: ClassDescriptor
|
||||||
get() = expandedConstructorDescriptor.baseDescriptorForSynthetic
|
get() = expandedConstructorDescriptor.baseDescriptorForSynthetic
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user