Simplify reportOnElement

Relates to #KT-38959
This commit is contained in:
Vladimir Dolzhenko
2021-03-24 09:28:05 +01:00
committed by Space
parent b385650bf0
commit 3d236b7171
3 changed files with 8 additions and 7 deletions
@@ -1330,8 +1330,7 @@ public class DescriptorResolver {
}
if (isStaticNestedClass(classDescriptor)) {
PsiElement onReport = (reportErrorsOn instanceof KtConstructorDelegationCall)
? CallResolverUtilKt.reportOnElement((KtConstructorDelegationCall) reportErrorsOn) : reportErrorsOn;
PsiElement onReport = CallResolverUtilKt.reportOnElement(reportErrorsOn);
trace.report(INACCESSIBLE_OUTER_CLASS_EXPRESSION.on(onReport, classDescriptor));
return false;
}
@@ -522,8 +522,7 @@ public class CallResolver {
@Nullable
private PsiElement calcReportOn(@NotNull KtConstructorDelegationReferenceExpression calleeExpression) {
PsiElement delegationCall = calleeExpression.getParent();
return delegationCall instanceof KtConstructorDelegationCall
? CallResolverUtilKt.reportOnElement((KtConstructorDelegationCall) delegationCall) : delegationCall;
return CallResolverUtilKt.reportOnElement(delegationCall);
}
@NotNull
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.resolve.calls.callResolverUtil
import com.google.common.collect.Lists
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
@@ -322,6 +323,8 @@ fun createResolutionCandidatesForConstructors(
}
}
internal fun KtConstructorDelegationCall.reportOnElement() = if (this.isImplicit) {
this.getStrictParentOfType<KtSecondaryConstructor>()!!
} else this
internal fun PsiElement.reportOnElement() =
(this as? KtConstructorDelegationCall)
?.takeIf { isImplicit }
?.let { getStrictParentOfType<KtSecondaryConstructor>()!! }
?: this