[FE 1.0] Remove usages of safeAs and cast from most of FE 1.0 modules:
- :core:descriptors - :core:descriptors.jvm - :core:deserialization - :compiler:cli - :compiler:frontend - :compiler:frontend:cfg - :compiler:frontend.java - :compiler:frontend.common.jvm - :compiler:psi - :compiler:resolution - :compiler:resolution.common - :compiler:resolution.common.jvm - :kotlin-reflect-api
This commit is contained in:
committed by
Space Team
parent
6afceb1e84
commit
d423782fac
+2
-3
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils.variableDescriptorForDeclaration
|
||||
import org.jetbrains.kotlin.util.javaslang.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) {
|
||||
private val containsDoWhile = pseudocode.rootPseudocode.containsDoWhile
|
||||
@@ -118,12 +117,12 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
|
||||
|
||||
private fun isValWithTrivialInitializer(variableDeclarationElement: KtDeclaration, descriptor: VariableDescriptor) =
|
||||
variableDeclarationElement is KtParameter || variableDeclarationElement is KtObjectDeclaration ||
|
||||
variableDeclarationElement.safeAs<KtVariableDeclaration>()?.isVariableWithTrivialInitializer(descriptor) == true
|
||||
(variableDeclarationElement as? KtVariableDeclaration)?.isVariableWithTrivialInitializer(descriptor) == true
|
||||
|
||||
private fun KtVariableDeclaration.isVariableWithTrivialInitializer(descriptor: VariableDescriptor): Boolean {
|
||||
if (descriptor.isPropertyWithoutBackingField()) return true
|
||||
if (isVar) return false
|
||||
return initializer != null || safeAs<KtProperty>()?.delegate != null || this is KtDestructuringDeclarationEntry
|
||||
return initializer != null || (this as? KtProperty)?.delegate != null || this is KtDestructuringDeclarationEntry
|
||||
}
|
||||
|
||||
private fun VariableDescriptor.isPropertyWithoutBackingField(): Boolean {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.contracts.parsing
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.contracts.parsing.ContractsDslNames.CALLS_IN_PLACE
|
||||
@@ -34,7 +33,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.types.typeUtil.isBoolean
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNullableAny
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
|
||||
object ContractsDslNames {
|
||||
@@ -91,6 +89,6 @@ fun DeclarationDescriptor.isEqualsDescriptor(): Boolean =
|
||||
this.returnType?.isBoolean() == true && this.valueParameters.singleOrNull()?.type?.isNullableAny() == true // signature matches
|
||||
|
||||
internal fun ResolvedCall<*>.firstArgumentAsExpressionOrNull(): KtExpression? =
|
||||
this.valueArgumentsByIndex?.firstOrNull()?.safeAs<ExpressionValueArgument>()?.valueArgument?.getArgumentExpression()
|
||||
(this.valueArgumentsByIndex?.firstOrNull() as? ExpressionValueArgument)?.valueArgument?.getArgumentExpression()
|
||||
|
||||
private fun DeclarationDescriptor.equalsDslDescriptor(dslName: Name): Boolean = this.name == dslName && this.isFromContractDsl()
|
||||
private fun DeclarationDescriptor.equalsDslDescriptor(dslName: Name): Boolean = this.name == dslName && this.isFromContractDsl()
|
||||
|
||||
+4
-5
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.contracts.parsing.*
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal class PsiConditionalEffectParser(
|
||||
collector: ContractParsingDiagnosticsCollector,
|
||||
@@ -33,11 +32,11 @@ internal class PsiConditionalEffectParser(
|
||||
val resolvedCall = expression.getResolvedCall(callContext.bindingContext) ?: return null
|
||||
if (!resolvedCall.resultingDescriptor.isImpliesCallDescriptor()) return null
|
||||
|
||||
val effect = contractParserDispatcher.parseEffect(resolvedCall.dispatchReceiver.safeAs<ExpressionReceiver>()?.expression)
|
||||
?: return null
|
||||
val effect = contractParserDispatcher.parseEffect((resolvedCall.dispatchReceiver as? ExpressionReceiver)?.expression)
|
||||
?: return null
|
||||
val condition = contractParserDispatcher.parseCondition(resolvedCall.firstArgumentAsExpressionOrNull())
|
||||
?: return null
|
||||
?: return null
|
||||
|
||||
return ConditionalEffectDeclaration(effect, condition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.types.typeUtil.constituentTypes
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal class DeclarationsCheckerBuilder(
|
||||
private val descriptorResolver: DescriptorResolver,
|
||||
@@ -415,7 +414,7 @@ class DeclarationsChecker(
|
||||
declaration
|
||||
}
|
||||
|
||||
if (descriptor.containingDeclaration.safeAs<MemberDescriptor>()?.isInlineOnly() == true) return
|
||||
if ((descriptor.containingDeclaration as? MemberDescriptor)?.isInlineOnly() == true) return
|
||||
|
||||
trace.report(BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER.on(reportOn))
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.resolve.calls.util.isOrOverridesSynthesized
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeCheckerImpl
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||
import java.util.*
|
||||
|
||||
class OverrideResolver(
|
||||
@@ -863,9 +862,8 @@ class OverrideResolver(
|
||||
|
||||
if (overriddenDescriptors.isEmpty()) {
|
||||
val containingDeclaration = declared.containingDeclaration
|
||||
val declaringClass = containingDeclaration.assertedCast<ClassDescriptor> {
|
||||
"Overrides may only be resolved in a class, but $declared comes from $containingDeclaration"
|
||||
}
|
||||
val declaringClass = containingDeclaration as? ClassDescriptor
|
||||
?: error("Overrides may only be resolved in a class, but $declared comes from $containingDeclaration")
|
||||
|
||||
val invisibleOverriddenDescriptor =
|
||||
findInvisibleOverriddenDescriptor(
|
||||
|
||||
@@ -15,23 +15,20 @@ import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isContractDescriptionCallPsiCheck
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isFirstStatement
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
/*
|
||||
* See KT-26386 and KT-30410
|
||||
*/
|
||||
fun disableContractsInsideContractsBlock(call: Call, descriptor: CallableDescriptor?, scope: LexicalScope, trace: BindingTrace) {
|
||||
call.callElement.safeAs<KtExpression>()?.let { callExpression ->
|
||||
(call.callElement as? KtExpression)?.let { callExpression ->
|
||||
if (callExpression.isFirstStatement() && callExpression.isContractDescriptionCallPsiCheck()) {
|
||||
if (descriptor?.isContractCallDescriptor() != true) {
|
||||
scope.ownerDescriptor
|
||||
.safeAs<FunctionDescriptor>()
|
||||
?.getUserData(ContractProviderKey)
|
||||
?.safeAs<LazyContractProvider>()
|
||||
?.setContractDescription(null)
|
||||
val functionDescriptor = scope.ownerDescriptor as? FunctionDescriptor
|
||||
val contractProvider = functionDescriptor?.getUserData(ContractProviderKey) as? LazyContractProvider
|
||||
contractProvider?.setContractDescription(null)
|
||||
} else {
|
||||
trace.record(BindingContext.IS_CONTRACT_DECLARATION_BLOCK, callExpression, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ import org.jetbrains.kotlin.types.error.ErrorScope
|
||||
import org.jetbrains.kotlin.types.error.ThrowingScope
|
||||
import org.jetbrains.kotlin.types.extensions.TypeAttributeTranslators
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import kotlin.math.min
|
||||
|
||||
class TypeResolver(
|
||||
@@ -416,7 +415,7 @@ class TypeResolver(
|
||||
for (parametersGroup in parametersByName.values) {
|
||||
if (parametersGroup.size < 2) continue
|
||||
for (parameter in parametersGroup) {
|
||||
val ktParameter = parameter.source.getPsi()?.safeAs<KtParameter>() ?: continue
|
||||
val ktParameter = (parameter.source.getPsi() as? KtParameter) ?: continue
|
||||
c.trace.report(DUPLICATE_PARAMETER_NAME_IN_FUNCTION_TYPE.on(ktParameter))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.error.ErrorScopeKind
|
||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.*
|
||||
|
||||
class CallCompleter(
|
||||
@@ -113,7 +112,7 @@ class CallCompleter(
|
||||
missingSupertypesResolver: MissingSupertypesResolver
|
||||
) {
|
||||
val call = context.call
|
||||
val explicitReceiver = call.explicitReceiver.safeAs<ReceiverValue>() ?: return
|
||||
val explicitReceiver = call.explicitReceiver as? ReceiverValue ?: return
|
||||
|
||||
MissingDependencySupertypeChecker.checkSupertypes(
|
||||
explicitReceiver.type, call.callElement, context.trace, missingSupertypesResolver
|
||||
@@ -329,7 +328,7 @@ class CallCompleter(
|
||||
}
|
||||
|
||||
private fun createTypeForConvertableConstant(constant: CompileTimeConstant<*>): SimpleType? {
|
||||
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
||||
val value = (constant.getValue(TypeUtils.NO_EXPECTED_TYPE) as? Number)?.toLong() ?: return null
|
||||
val typeConstructor = IntegerValueTypeConstructor(value, moduleDescriptor, constant.parameters)
|
||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||
|
||||
+12
-15
@@ -51,8 +51,6 @@ import org.jetbrains.kotlin.types.model.freshTypeConstructor
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNullableNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -184,7 +182,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
override fun onCallReceiver(callReceiver: SimpleKotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
|
||||
when (diagnostic.javaClass) {
|
||||
UnsafeCallError::class.java -> {
|
||||
val unsafeCallErrorDiagnostic = diagnostic.cast<UnsafeCallError>()
|
||||
val unsafeCallErrorDiagnostic = diagnostic as UnsafeCallError
|
||||
val isForImplicitInvoke = when (callReceiver) {
|
||||
is ReceiverExpressionKotlinCallArgument -> callReceiver.isForImplicitInvoke
|
||||
else -> unsafeCallErrorDiagnostic.isForImplicitInvoke
|
||||
@@ -248,8 +246,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
trace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(callArgument.psiCallArgument.valueArgument.asElement()))
|
||||
|
||||
NoneCallableReferenceCallCandidates::class.java -> {
|
||||
val expression = diagnostic.cast<NoneCallableReferenceCallCandidates>()
|
||||
.argument.safeAs<CallableReferenceKotlinCallArgumentImpl>()?.ktCallableReferenceExpression
|
||||
val argument = (diagnostic as? NoneCallableReferenceCallCandidates)?.argument
|
||||
val expression = (argument as? CallableReferenceKotlinCallArgumentImpl)?.ktCallableReferenceExpression
|
||||
if (expression != null) {
|
||||
trace.report(UNRESOLVED_REFERENCE.on(expression.callableReference, expression.callableReference))
|
||||
}
|
||||
@@ -260,7 +258,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val expression = when (val psiExpression = ambiguityDiagnostic.argument.psiExpression) {
|
||||
is KtPsiUtil.KtExpressionWrapper -> psiExpression.baseExpression
|
||||
else -> psiExpression
|
||||
}.safeAs<KtCallableReferenceExpression>()
|
||||
} as? KtCallableReferenceExpression
|
||||
|
||||
val candidates = ambiguityDiagnostic.candidates.map { it.candidate }
|
||||
if (expression != null) {
|
||||
@@ -380,8 +378,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
override fun onCallArgumentSpread(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
|
||||
when (diagnostic.javaClass) {
|
||||
NonVarargSpread::class.java -> {
|
||||
val castedPsiCallArgument = callArgument.safeAs<PSIKotlinCallArgument>()
|
||||
val castedCallArgument = callArgument.safeAs<ExpressionKotlinCallArgumentImpl>()
|
||||
val castedPsiCallArgument = callArgument as? PSIKotlinCallArgument
|
||||
val castedCallArgument = callArgument as? ExpressionKotlinCallArgumentImpl
|
||||
|
||||
if (castedCallArgument != null) {
|
||||
val spreadElement = castedCallArgument.valueArgument.getSpreadElement()
|
||||
@@ -488,7 +486,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val typeMismatchDiagnostic = if (isWarning) TYPE_MISMATCH_WARNING else TYPE_MISMATCH
|
||||
val report = if (isWarning) trace::reportDiagnosticOnce else trace::report
|
||||
argument?.let {
|
||||
it.safeAs<LambdaKotlinCallArgument>()?.let lambda@{ lambda ->
|
||||
(it as? LambdaKotlinCallArgument)?.let lambda@{ lambda ->
|
||||
val parameterTypes = lambda.parametersTypes?.toList() ?: return@lambda
|
||||
val index = parameterTypes.indexOf(error.upperKotlinType.unwrap())
|
||||
val lambdaExpression = lambda.psiExpression as? KtLambdaExpression ?: return@lambda
|
||||
@@ -516,7 +514,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
|
||||
(position as? ExpectedTypeConstraintPositionImpl)?.let {
|
||||
val call = it.topLevelCall.psiKotlinCall.psiCall.callElement.safeAs<KtExpression>()
|
||||
val call = it.topLevelCall.psiKotlinCall.psiCall.callElement as? KtExpression
|
||||
val inferredType =
|
||||
if (!error.lowerKotlinType.isNullableNothing()) error.lowerKotlinType
|
||||
else error.upperKotlinType.makeNullable()
|
||||
@@ -549,7 +547,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
if (morePreciseDiagnosticExists) return
|
||||
|
||||
val call = it.resolvedAtom?.atom?.safeAs<PSIKotlinCall>()?.psiCall ?: call
|
||||
val call = (it.resolvedAtom?.atom as? PSIKotlinCall)?.psiCall ?: call
|
||||
val expression = call.calleeExpression ?: return
|
||||
|
||||
trace.reportDiagnosticOnce(typeMismatchDiagnostic.on(expression, error.upperKotlinType, error.lowerKotlinType))
|
||||
@@ -566,9 +564,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
error as CapturedTypeFromSubtyping
|
||||
val position = error.position
|
||||
val argumentPosition: ArgumentConstraintPositionImpl? =
|
||||
position.safeAs<ArgumentConstraintPositionImpl>()
|
||||
?: position.safeAs<IncorporationConstraintPosition>()
|
||||
?.from.safeAs<ArgumentConstraintPositionImpl>()
|
||||
position as? ArgumentConstraintPositionImpl
|
||||
?: (position as? IncorporationConstraintPosition)?.from as? ArgumentConstraintPositionImpl
|
||||
|
||||
argumentPosition?.let {
|
||||
val expression = it.argument.psiExpression ?: return
|
||||
@@ -689,7 +686,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
|
||||
private fun reportNullabilityMismatchDiagnostic(callArgument: KotlinCallArgument, diagnostic: ArgumentNullabilityMismatchDiagnostic) {
|
||||
val expression = callArgument.safeAs<PSIKotlinCallArgument>()?.valueArgument?.getArgumentExpression()?.let {
|
||||
val expression = (callArgument as? PSIKotlinCallArgument)?.valueArgument?.getArgumentExpression()?.let {
|
||||
KtPsiUtil.deparenthesize(it) ?: it
|
||||
}
|
||||
if (expression != null) {
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.getAbbreviation
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object DslMarkerUtils {
|
||||
|
||||
@@ -33,13 +32,12 @@ object DslMarkerUtils {
|
||||
fun extractDslMarkerFqNames(receiver: ReceiverValue): DslMarkersFromReceiver {
|
||||
val errorLevel = extractDslMarkerFqNames(receiver.type)
|
||||
|
||||
val deprecationLevel =
|
||||
receiver.safeAs<ExtensionReceiver>()
|
||||
?.declarationDescriptor
|
||||
?.safeAs<FunctionDescriptor>()
|
||||
?.getUserData(FunctionTypeAnnotationsKey)
|
||||
?.let(Annotations::extractDslMarkerFqNames)
|
||||
?.toSet() ?: emptySet()
|
||||
val functionDescriptor = (receiver as? ExtensionReceiver)?.declarationDescriptor as? FunctionDescriptor
|
||||
val deprecationLevel = functionDescriptor
|
||||
?.getUserData(FunctionTypeAnnotationsKey)
|
||||
?.let(Annotations::extractDslMarkerFqNames)
|
||||
?.toSet()
|
||||
?: emptySet()
|
||||
|
||||
return DslMarkersFromReceiver(errorLevel, deprecationLevel)
|
||||
}
|
||||
@@ -51,7 +49,7 @@ object DslMarkerUtils {
|
||||
|
||||
kotlinType.getAbbreviation()?.constructor?.declarationDescriptor?.run {
|
||||
result.addAll(annotations.extractDslMarkerFqNames())
|
||||
safeAs<TypeAliasDescriptor>()?.run {
|
||||
(this as? TypeAliasDescriptor)?.run {
|
||||
result.addAll(extractDslMarkerFqNames(this.underlyingType))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val SPECIAL_FUNCTION_NAMES = ResolveConstruct.values().map { it.specialFunctionName }.toSet()
|
||||
|
||||
@@ -133,7 +132,7 @@ class GenericCandidateResolver(
|
||||
|
||||
if (context.candidateCall is VariableAsFunctionResolvedCall) return
|
||||
|
||||
val candidateDescriptor = context.candidateCall.candidateDescriptor.safeAs<FunctionDescriptor>() ?: return
|
||||
val candidateDescriptor = context.candidateCall.candidateDescriptor as? FunctionDescriptor ?: return
|
||||
|
||||
val binaryParent = context.call.calleeExpression?.getBinaryWithTypeParent() ?: return
|
||||
val operationType = binaryParent.operationReference.getReferencedNameElementType().takeIf {
|
||||
@@ -531,4 +530,4 @@ private fun KotlinType.isApplicableExpectedTypeForCallableReference(): Boolean {
|
||||
ReflectionTypes.isBaseTypeForNumberedReferenceTypes(this) ||
|
||||
ReflectionTypes.isNumberedKFunctionOrKSuspendFunction(this) ||
|
||||
ReflectionTypes.isNumberedKPropertyOrKMutablePropertyType(this)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-13
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isInfixCall
|
||||
@@ -15,7 +14,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.serialization.deserialization.KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object LambdaWithSuspendModifierCallChecker : CallChecker {
|
||||
|
||||
@@ -23,7 +21,7 @@ object LambdaWithSuspendModifierCallChecker : CallChecker {
|
||||
val descriptor = resolvedCall.candidateDescriptor
|
||||
val call = resolvedCall.call
|
||||
val calleeName = call.referencedName()
|
||||
val variableCalleeName = resolvedCall.safeAs<VariableAsFunctionResolvedCall>()?.variableCall?.call?.referencedName()
|
||||
val variableCalleeName = (resolvedCall as? VariableAsFunctionResolvedCall)?.variableCall?.call?.referencedName()
|
||||
|
||||
if (calleeName != "suspend" && variableCalleeName != "suspend" && descriptor.name.asString() != "suspend") return
|
||||
|
||||
@@ -48,22 +46,19 @@ object LambdaWithSuspendModifierCallChecker : CallChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Call.hasFormOfSuspendModifierForLambdaOrFun() =
|
||||
private fun Call.hasFormOfSuspendModifierForLambdaOrFun(): Boolean =
|
||||
!isCallableReference()
|
||||
&& typeArguments.isEmpty()
|
||||
&& (hasNoArgumentListButDanglingLambdas() || isInfixWithRightLambda() || isInfixWithRightFun())
|
||||
|
||||
private fun Call.referencedName() =
|
||||
calleeExpression?.safeAs<KtSimpleNameExpression>()?.getReferencedName()
|
||||
private fun Call.referencedName(): String? = (calleeExpression as? KtSimpleNameExpression)?.getReferencedName()
|
||||
|
||||
private fun Call.hasNoArgumentListButDanglingLambdas() =
|
||||
private fun Call.hasNoArgumentListButDanglingLambdas(): Boolean =
|
||||
valueArgumentList?.leftParenthesis == null && functionLiteralArguments.isNotEmpty()
|
||||
|
||||
private fun Call.isInfixWithRightLambda() =
|
||||
isInfixCall(this)
|
||||
&& callElement.safeAs<KtBinaryExpression>()?.right is KtLambdaExpression
|
||||
private fun Call.isInfixWithRightLambda(): Boolean =
|
||||
isInfixCall(this) && (callElement as? KtBinaryExpression)?.right is KtLambdaExpression
|
||||
|
||||
private fun Call.isInfixWithRightFun() =
|
||||
isInfixCall(this)
|
||||
&& callElement.safeAs<KtBinaryExpression>()?.right is KtNamedFunction
|
||||
private fun Call.isInfixWithRightFun(): Boolean =
|
||||
isInfixCall(this) && (callElement as? KtBinaryExpression)?.right is KtNamedFunction
|
||||
}
|
||||
|
||||
+2
-3
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.resolve.calls.tower.SimplePSIKotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||
import org.jetbrains.kotlin.types.FlexibleType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object NullableVarargArgumentCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
@@ -33,7 +32,7 @@ object NullableVarargArgumentCallChecker : CallChecker {
|
||||
if (!arg.isSpread || arg !is SimplePSIKotlinCallArgument) continue
|
||||
|
||||
val spreadElement = arg.valueArgument.getSpreadElement() ?: continue
|
||||
val receiver = arg.receiver.safeAs<ReceiverValueWithSmartCastInfo>() ?: continue
|
||||
val receiver = (arg.receiver as? ReceiverValueWithSmartCastInfo) ?: continue
|
||||
|
||||
val type = if (receiver.stableType.constructor is TypeVariableTypeConstructor) {
|
||||
context.trace.bindingContext[EXPRESSION_TYPE_INFO, arg.valueArgument.getArgumentExpression()]?.type
|
||||
@@ -48,4 +47,4 @@ object NullableVarargArgumentCallChecker : CallChecker {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -31,8 +31,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val COROUTINE_CONTEXT_FQ_NAME =
|
||||
StandardNames.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("coroutineContext"))
|
||||
@@ -48,10 +46,12 @@ fun PropertyDescriptor.isBuiltInCoroutineContext() =
|
||||
|
||||
private val ALLOWED_SCOPE_KINDS = setOf(LexicalScopeKind.FUNCTION_INNER_SCOPE, LexicalScopeKind.FUNCTION_HEADER_FOR_DESTRUCTURING)
|
||||
|
||||
fun findEnclosingSuspendFunction(context: CallCheckerContext): FunctionDescriptor? =
|
||||
context.scope.parentsWithSelf.firstOrNull {
|
||||
it is LexicalScope && it.kind in ALLOWED_SCOPE_KINDS && it.ownerDescriptor.safeAs<FunctionDescriptor>()?.isSuspend == true
|
||||
}?.cast<LexicalScope>()?.ownerDescriptor?.cast()
|
||||
fun findEnclosingSuspendFunction(context: CallCheckerContext): FunctionDescriptor? {
|
||||
val scope = context.scope.parentsWithSelf.firstOrNull {
|
||||
it is LexicalScope && it.kind in ALLOWED_SCOPE_KINDS && (it.ownerDescriptor as? FunctionDescriptor)?.isSuspend == true
|
||||
} as LexicalScope?
|
||||
return scope?.ownerDescriptor as FunctionDescriptor?
|
||||
}
|
||||
|
||||
object CoroutineSuspendCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
|
||||
+5
-4
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.types.model.safeSubstitute
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.shouldBeUpdated
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class BuilderInferenceSession(
|
||||
psiCallResolver: PSICallResolver,
|
||||
@@ -218,7 +217,7 @@ class BuilderInferenceSession(
|
||||
fun getUsedStubTypes(): Set<StubTypeForBuilderInference> = stubsForPostponedVariables.values.toSet()
|
||||
|
||||
fun getCurrentSubstitutor(): NewTypeSubstitutor =
|
||||
commonSystem.buildCurrentSubstitutor().cast<NewTypeSubstitutor>().takeIf { !it.isEmpty } ?: EmptySubstitutor
|
||||
(commonSystem.buildCurrentSubstitutor() as NewTypeSubstitutor).takeIf { !it.isEmpty } ?: EmptySubstitutor
|
||||
|
||||
private fun arePostponedVariablesInferred() = commonSystem.notFixedTypeVariables.isEmpty()
|
||||
|
||||
@@ -267,7 +266,8 @@ class BuilderInferenceSession(
|
||||
updateAllCalls(resultingSubstitutor)
|
||||
}
|
||||
|
||||
return commonSystem.fixedTypeVariables.cast() // TODO: SUB
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return commonSystem.fixedTypeVariables as Map<TypeConstructor, UnwrappedType> // TODO: SUB
|
||||
}
|
||||
|
||||
private fun getNestedBuilderInferenceSessions() = buildList {
|
||||
@@ -495,8 +495,9 @@ class BuilderInferenceSession(
|
||||
val resultingCallSubstitutor = storage.fixedTypeVariables.entries
|
||||
.associate { it.key to nonFixedTypesToResultSubstitutor.safeSubstitute(it.value as UnwrappedType) } // TODO: SUB
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val resultingSubstitutor =
|
||||
NewTypeSubstitutorByConstructorMap((resultingCallSubstitutor + nonFixedTypesToResult).cast()) // TODO: SUB
|
||||
NewTypeSubstitutorByConstructorMap((resultingCallSubstitutor + nonFixedTypesToResult) as Map<TypeConstructor, UnwrappedType>) // TODO: SUB
|
||||
|
||||
val atomCompleter = createResolvedAtomCompleter(
|
||||
resultingSubstitutor,
|
||||
|
||||
+4
-3
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.types.model.requireOrDescribe
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.defaultProjections
|
||||
import org.jetbrains.kotlin.types.typeUtil.isDefaultBound
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import java.util.*
|
||||
|
||||
open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystemBuilderImpl.Mode.INFERENCE) : ConstraintSystem.Builder {
|
||||
@@ -432,8 +431,10 @@ open class ConstraintSystemBuilderImpl(private val mode: Mode = ConstraintSystem
|
||||
get() = SimpleClassicTypeSystemContext
|
||||
var counter = 0
|
||||
|
||||
override fun registerTypeVariables(typeParameters: Collection<TypeParameterMarker>) =
|
||||
registerTypeVariables(CallHandle.NONE, typeParameters.cast())
|
||||
override fun registerTypeVariables(typeParameters: Collection<TypeParameterMarker>): TypeSubstitutor {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return registerTypeVariables(CallHandle.NONE, typeParameters as Collection<TypeParameterDescriptor>)
|
||||
}
|
||||
|
||||
override fun addSubtypeConstraint(subType: KotlinTypeMarker, superType: KotlinTypeMarker) {
|
||||
requireOrDescribe(subType is UnwrappedType, subType)
|
||||
|
||||
+2
-3
@@ -53,7 +53,6 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
data class LambdaContextInfo(
|
||||
var typeInfo: KotlinTypeInfo? = null,
|
||||
@@ -310,7 +309,7 @@ class KotlinResolutionCallbacksImpl(
|
||||
val returnType = descriptor.returnType ?: return false
|
||||
if (!isPrimitiveTypeOrNullablePrimitiveType(returnType) || !isPrimitiveTypeOrNullablePrimitiveType(expectedType)) return false
|
||||
|
||||
val callElement = resolvedAtom.atom.psiKotlinCall.psiCall.callElement.safeAs<KtExpression>() ?: return false
|
||||
val callElement = (resolvedAtom.atom.psiKotlinCall.psiCall.callElement as? KtExpression) ?: return false
|
||||
val expression = findCommonParent(callElement, resolvedAtom.atom.psiKotlinCall.explicitReceiver)
|
||||
|
||||
val temporaryBindingTrace = TemporaryBindingTrace.create(
|
||||
@@ -327,7 +326,7 @@ class KotlinResolutionCallbacksImpl(
|
||||
|
||||
override fun getExpectedTypeFromAsExpressionAndRecordItInTrace(resolvedAtom: ResolvedCallAtom): UnwrappedType? {
|
||||
val candidateDescriptor = resolvedAtom.candidateDescriptor as? FunctionDescriptor ?: return null
|
||||
val call = resolvedAtom.atom.safeAs<PSIKotlinCall>()?.psiCall ?: return null
|
||||
val call = (resolvedAtom.atom as? PSIKotlinCall)?.psiCall ?: return null
|
||||
|
||||
if (call.typeArgumentList != null || !candidateDescriptor.isFunctionForExpectTypeFromCastFeature()) return null
|
||||
val binaryParent = call.calleeExpression?.getBinaryWithTypeParent() ?: return null
|
||||
|
||||
+3
-6
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -29,7 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.util.isInfixCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSuperOrDelegatingConstructorCall
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionStatelessCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.SimpleConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.isBuilderInferenceCall
|
||||
@@ -40,10 +39,8 @@ import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.results.SimpleConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeRefinerImpl
|
||||
import org.jetbrains.kotlin.types.TypeIntersector
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class KotlinResolutionStatelessCallbacksImpl(
|
||||
private val deprecationResolver: DeprecationResolver,
|
||||
@@ -92,8 +89,8 @@ class KotlinResolutionStatelessCallbacksImpl(
|
||||
override fun getScopeTowerForCallableReferenceArgument(argument: CallableReferenceKotlinCallArgument): ImplicitScopeTower =
|
||||
(argument as CallableReferenceKotlinCallArgumentImpl).scopeTowerForResolution
|
||||
|
||||
override fun getVariableCandidateIfInvoke(functionCall: KotlinCall) =
|
||||
functionCall.safeAs<PSIKotlinCallForInvoke>()?.variableCall
|
||||
override fun getVariableCandidateIfInvoke(functionCall: KotlinCall): ResolutionCandidate? =
|
||||
(functionCall as? PSIKotlinCallForInvoke)?.variableCall
|
||||
|
||||
override fun isBuilderInferenceCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean =
|
||||
isBuilderInferenceCall(parameter, argument.psiCallArgument.valueArgument, languageVersionSettings)
|
||||
|
||||
+4
-5
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class KotlinToResolvedCallTransformer(
|
||||
private val callCheckers: Iterable<CallChecker>,
|
||||
@@ -170,7 +169,7 @@ class KotlinToResolvedCallTransformer(
|
||||
): NewAbstractResolvedCall<D> {
|
||||
val result = transformToResolvedCall<D>(candidate, trace, substitutor, diagnostics)
|
||||
val psiKotlinCall = candidate.atom.psiKotlinCall
|
||||
val tracing = psiKotlinCall.safeAs<PSIKotlinCallForInvoke>()?.baseCall?.tracingStrategy ?: psiKotlinCall.tracingStrategy
|
||||
val tracing = (psiKotlinCall as? PSIKotlinCallForInvoke)?.baseCall?.tracingStrategy ?: psiKotlinCall.tracingStrategy
|
||||
|
||||
tracing.bindReference(trace, result)
|
||||
tracing.bindResolvedCall(trace, result)
|
||||
@@ -393,7 +392,7 @@ class KotlinToResolvedCallTransformer(
|
||||
}
|
||||
|
||||
private fun createTypeForConvertableConstant(constant: CompileTimeConstant<*>): SimpleType? {
|
||||
val value = constant.getValue(TypeUtils.NO_EXPECTED_TYPE).safeAs<Number>()?.toLong() ?: return null
|
||||
val value = (constant.getValue(TypeUtils.NO_EXPECTED_TYPE) as? Number)?.toLong() ?: return null
|
||||
val typeConstructor = IntegerLiteralTypeConstructor(value, moduleDescriptor, constant.parameters)
|
||||
return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||
TypeAttributes.Empty, typeConstructor, emptyList(), false,
|
||||
@@ -462,8 +461,8 @@ class KotlinToResolvedCallTransformer(
|
||||
}
|
||||
|
||||
internal fun bind(trace: BindingTrace, resolvedCall: ResolvedCall<*>) {
|
||||
resolvedCall.safeAs<NewAbstractResolvedCall<*>>()?.let { bind(trace, it) }
|
||||
resolvedCall.safeAs<NewVariableAsFunctionResolvedCallImpl>()?.let { bind(trace, it) }
|
||||
(resolvedCall as? NewAbstractResolvedCall<*>)?.let { bind(trace, it) }
|
||||
(resolvedCall as? NewVariableAsFunctionResolvedCallImpl)?.let { bind(trace, it) }
|
||||
}
|
||||
|
||||
fun reportDiagnostics(
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class SimpleTypeArgumentImpl(
|
||||
val typeProjection: KtTypeProjection,
|
||||
@@ -60,8 +59,8 @@ val KotlinCallArgument.psiCallArgument: PSIKotlinCallArgument
|
||||
val KotlinCallArgument.psiExpression: KtExpression?
|
||||
get() {
|
||||
return when (this) {
|
||||
is ReceiverExpressionKotlinCallArgument -> receiver.receiverValue.safeAs<ExpressionReceiver>()?.expression
|
||||
is QualifierReceiverKotlinCallArgument -> receiver.safeAs<Qualifier>()?.expression
|
||||
is ReceiverExpressionKotlinCallArgument -> (receiver.receiverValue as? ExpressionReceiver)?.expression
|
||||
is QualifierReceiverKotlinCallArgument -> (receiver as? Qualifier)?.expression
|
||||
is EmptyLabeledReturn -> returnExpression
|
||||
else -> psiCallArgument.valueArgument.getArgumentExpression()
|
||||
}
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.CastImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
override val resolvedCallAtom: ResolvedCallAtom,
|
||||
@@ -228,7 +227,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
else -> null
|
||||
} as? ArgumentConstraintPositionImpl ?: return@forEach
|
||||
|
||||
val argument = position.argument.safeAs<PSIKotlinCallArgument>()?.valueArgument ?: return@forEach
|
||||
val argument = (position.argument as? PSIKotlinCallArgument)?.valueArgument ?: return@forEach
|
||||
result += argument to it
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -14,13 +14,12 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeApproximator
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class NewVariableAsFunctionResolvedCallImpl(
|
||||
override val variableCall: NewAbstractResolvedCall<VariableDescriptor>,
|
||||
override val functionCall: NewAbstractResolvedCall<FunctionDescriptor>,
|
||||
) : VariableAsFunctionResolvedCall, NewAbstractResolvedCall<FunctionDescriptor>() {
|
||||
val baseCall: PSIKotlinCallImpl = functionCall.psiKotlinCall.cast<PSIKotlinCallForInvoke>().baseCall
|
||||
val baseCall: PSIKotlinCallImpl = (functionCall.psiKotlinCall as PSIKotlinCallForInvoke).baseCall
|
||||
|
||||
override val resolvedCallAtom: ResolvedCallAtom? = functionCall.resolvedCallAtom
|
||||
override val psiKotlinCall: PSIKotlinCall = functionCall.psiKotlinCall
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ class ResolvedAtomCompleter(
|
||||
?: return (subResolvedAtoms!!.single() as ResolvedLambdaAtom).isCoercedToUnit
|
||||
val returnTypes =
|
||||
resultArgumentsInfo.nonErrorArguments.map {
|
||||
val type = it.safeAs<SimpleKotlinCallArgument>()?.receiver?.receiverValue?.type ?: return@map null
|
||||
val type = (it as? SimpleKotlinCallArgument)?.receiver?.receiverValue?.type ?: return@map null
|
||||
val unwrappedType = when (type) {
|
||||
is WrappedType -> type.unwrap()
|
||||
is UnwrappedType -> type
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
// resolved call
|
||||
@@ -279,11 +278,11 @@ fun ResolvedCall<*>.getFirstArgumentExpression(): KtExpression? =
|
||||
valueArgumentsByIndex?.run { get(0).arguments[0].getArgumentExpression() }
|
||||
|
||||
fun ResolvedCall<*>.getReceiverExpression(): KtExpression? =
|
||||
extensionReceiver.safeAs<ExpressionReceiver>()?.expression ?: dispatchReceiver.safeAs<ExpressionReceiver>()?.expression
|
||||
(extensionReceiver as? ExpressionReceiver)?.expression ?: (dispatchReceiver as? ExpressionReceiver)?.expression
|
||||
|
||||
val KtLambdaExpression.isTrailingLambdaOnNewLIne
|
||||
get(): Boolean {
|
||||
parent?.safeAs<KtLambdaArgument>()?.let { lambdaArgument ->
|
||||
(parent as? KtLambdaArgument)?.let { lambdaArgument ->
|
||||
var prevSibling = lambdaArgument.prevSibling
|
||||
|
||||
while (prevSibling != null && prevSibling !is KtElement) {
|
||||
|
||||
+1
-2
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.getSinceVersion
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object DeprecatedSinceKotlinAnnotationChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
@@ -91,7 +90,7 @@ object DeprecatedSinceKotlinAnnotationChecker : DeclarationChecker {
|
||||
context: DeclarationCheckerContext,
|
||||
reportOn: PsiElement
|
||||
) {
|
||||
val argumentValue = argumentValue(name).safeAs<StringValue>()?.value
|
||||
val argumentValue = (argumentValue(name) as? StringValue)?.value
|
||||
if (argumentValue != null && (parsedVersion == null || !argumentValue.matches(RequireKotlinConstants.VERSION_REGEX))) {
|
||||
context.trace.reportDiagnosticOnce(
|
||||
Errors.ILLEGAL_KOTLIN_VERSION_STRING_VALUE.on(
|
||||
|
||||
+5
-7
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility.*
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceFile
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.io.File
|
||||
|
||||
class ExpectedActualDeclarationChecker(
|
||||
@@ -196,7 +195,7 @@ class ExpectedActualDeclarationChecker(
|
||||
private fun reportMissingActualModifier(actual: MemberDescriptor, reportOn: KtNamedDeclaration?, trace: BindingTrace) {
|
||||
if (actual.isActual) return
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val reportOn = reportOn ?: actual.source.safeAs<KotlinSourceElement>()?.psi.safeAs<KtNamedDeclaration>() ?: return
|
||||
val reportOn = reportOn ?: (actual.source as? KotlinSourceElement)?.psi as? KtNamedDeclaration ?: return
|
||||
|
||||
if (requireActualModifier(actual)) {
|
||||
trace.report(Errors.ACTUAL_MISSING.on(reportOn))
|
||||
@@ -222,11 +221,10 @@ class ExpectedActualDeclarationChecker(
|
||||
}
|
||||
}
|
||||
|
||||
private fun sourceFile(descriptor: MemberDescriptor): File? =
|
||||
descriptor.source
|
||||
.containingFile
|
||||
.safeAs<PsiSourceFile>()
|
||||
?.run { VfsUtilCore.virtualToIoFile(psiFile.virtualFile) }
|
||||
private fun sourceFile(descriptor: MemberDescriptor): File? {
|
||||
val containingFile = descriptor.source.containingFile as? PsiSourceFile ?: return null
|
||||
return VfsUtilCore.virtualToIoFile(containingFile.psiFile.virtualFile)
|
||||
}
|
||||
|
||||
private fun checkActualDeclarationHasExpected(
|
||||
reportOn: KtNamedDeclaration,
|
||||
|
||||
+1
-2
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
private val javaLangCloneable = FqNameUnsafe("java.lang.Cloneable")
|
||||
|
||||
@@ -92,7 +91,7 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
var baseParametersOk = true
|
||||
val baseParameterTypes = descriptor.safeAs<ClassDescriptor>()?.defaultType?.substitutedUnderlyingTypes() ?: emptyList()
|
||||
val baseParameterTypes = (descriptor as? ClassDescriptor)?.defaultType?.substitutedUnderlyingTypes() ?: emptyList()
|
||||
|
||||
for ((baseParameter, baseParameterType) in primaryConstructor.valueParameters zip baseParameterTypes) {
|
||||
if (!isParameterAcceptableForInlineClass(baseParameter)) {
|
||||
|
||||
+2
-4
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getAnnotationRetention
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class OptInMarkerDeclarationAnnotationChecker(private val module: ModuleDescriptor) : AdditionalAnnotationChecker {
|
||||
override fun checkEntries(
|
||||
@@ -43,9 +42,8 @@ class OptInMarkerDeclarationAnnotationChecker(private val module: ModuleDescript
|
||||
val annotation = trace.bindingContext.get(BindingContext.ANNOTATION, entry) ?: continue
|
||||
when (annotation.fqName) {
|
||||
OptInNames.OPT_IN_FQ_NAME -> {
|
||||
val annotationClasses =
|
||||
annotation.allValueArguments[OptInNames.OPT_IN_ANNOTATION_CLASS]
|
||||
.safeAs<ArrayValue>()?.value.orEmpty()
|
||||
val annotationClasses = (annotation.allValueArguments[OptInNames.OPT_IN_ANNOTATION_CLASS] as? ArrayValue)
|
||||
?.value.orEmpty()
|
||||
checkOptInUsage(annotationClasses, trace, entry)
|
||||
}
|
||||
OptInNames.SUBCLASS_OPT_IN_REQUIRED_FQ_NAME -> {
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal sealed class DeprecatedByAnnotation(
|
||||
val annotation: AnnotationDescriptor,
|
||||
@@ -27,12 +26,12 @@ internal sealed class DeprecatedByAnnotation(
|
||||
override val propagatesToOverrides: Boolean
|
||||
) : DescriptorBasedDeprecationInfo() {
|
||||
override val message: String?
|
||||
get() = annotation.argumentValue("message")?.safeAs<StringValue>()?.value
|
||||
get() = (annotation.argumentValue("message") as? StringValue)?.value
|
||||
|
||||
internal val replaceWithValue: String?
|
||||
get() {
|
||||
val replaceWithAnnotation = annotation.argumentValue(Deprecated::replaceWith.name)?.safeAs<AnnotationValue>()?.value
|
||||
return replaceWithAnnotation?.argumentValue(ReplaceWith::expression.name)?.safeAs<StringValue>()?.value
|
||||
val replaceWithAnnotation = (annotation.argumentValue(Deprecated::replaceWith.name) as? AnnotationValue)?.value
|
||||
return (replaceWithAnnotation?.argumentValue(ReplaceWith::expression.name) as? StringValue)?.value
|
||||
}
|
||||
|
||||
class StandardDeprecated(
|
||||
@@ -41,7 +40,7 @@ internal sealed class DeprecatedByAnnotation(
|
||||
propagatesToOverrides: Boolean
|
||||
) : DeprecatedByAnnotation(annotation, target, propagatesToOverrides) {
|
||||
override val deprecationLevel: DeprecationLevelValue
|
||||
get() = when (annotation.argumentValue("level")?.safeAs<EnumValue>()?.enumEntryName?.asString()) {
|
||||
get() = when ((annotation.argumentValue("level") as? EnumValue)?.enumEntryName?.asString()) {
|
||||
"WARNING" -> WARNING
|
||||
"ERROR" -> ERROR
|
||||
"HIDDEN" -> HIDDEN
|
||||
|
||||
+1
-2
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -270,7 +269,7 @@ class DeprecationResolver(
|
||||
languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
|
||||
|
||||
private fun getDeprecationFromUserData(target: DeclarationDescriptor): DescriptorBasedDeprecationInfo? =
|
||||
target.safeAs<CallableDescriptor>()?.getUserData(DEPRECATED_FUNCTION_KEY)
|
||||
(target as? CallableDescriptor)?.getUserData(DEPRECATED_FUNCTION_KEY)
|
||||
|
||||
private fun getDeprecationByVersionRequirement(target: DeclarationDescriptor): List<DeprecatedByVersionRequirement> {
|
||||
fun createVersion(version: String): MavenComparableVersion? = try {
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
fun DescriptorBasedDeprecationInfo.deprecatedByOverriddenMessage(): String? = (this as? DeprecatedByOverridden)?.additionalMessage()
|
||||
|
||||
@@ -25,7 +24,7 @@ fun DescriptorBasedDeprecationInfo.deprecatedByAnnotationReplaceWithExpression()
|
||||
|
||||
// The function extracts value of warningSince/errorSince/hiddenSince from DeprecatedSinceKotlin annotation
|
||||
fun AnnotationDescriptor.getSinceVersion(name: String): ApiVersion? =
|
||||
argumentValue(name)?.safeAs<StringValue>()?.value?.takeUnless(String::isEmpty)?.let(ApiVersion.Companion::parse)
|
||||
(argumentValue(name) as? StringValue)?.value?.takeUnless(String::isEmpty)?.let(ApiVersion.Companion::parse)
|
||||
|
||||
fun computeLevelForDeprecatedSinceKotlin(annotation: AnnotationDescriptor, apiVersion: ApiVersion): DeprecationLevelValue? {
|
||||
val hiddenSince = annotation.getSinceVersion("hiddenSince")
|
||||
|
||||
Reference in New Issue
Block a user