mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-CR-54180 add assertion for too deep inference process: better assertion message
GitOrigin-RevId: 3ebba7a02b7a99af1217e9c5b93d27c76ee348f7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d968ee3aec
commit
5e329f1cbe
+6
-1
@@ -31,6 +31,7 @@ class CollectingGroovyInferenceSession(
|
||||
|
||||
companion object {
|
||||
private const val MAX_DEPTH = 127
|
||||
private const val OBSERVING_DISTANCE = 10
|
||||
|
||||
fun getContextSubstitutor(resolveResult: GroovyMethodResult,
|
||||
nearestCall: GrCall): PsiSubstitutor = RecursionManager.doPreventingRecursion(resolveResult, true) {
|
||||
@@ -70,7 +71,11 @@ class CollectingGroovyInferenceSession(
|
||||
result: GroovyResolveResult,
|
||||
f: (GroovyInferenceSession) -> Unit) {
|
||||
if (depth >= MAX_DEPTH) {
|
||||
throw AssertionError("Inference process has gone too deep on ${result.element?.text}")
|
||||
var place = context
|
||||
repeat(OBSERVING_DISTANCE) {
|
||||
place = place.parent ?: place
|
||||
}
|
||||
throw AssertionError("Inference process has gone too deep on ${context.text} in ${place.text}")
|
||||
}
|
||||
val nestedSession = CollectingGroovyInferenceSession(params, context, siteSubstitutor, proxyMethodMapping, ignoreClosureArguments, depth + 1)
|
||||
nestedSession.propagateVariables(this)
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ class CommonDriver private constructor(private val targetParameters: Set<GrParam
|
||||
else if (call is GrConstructorInvocation) {
|
||||
val resolveResult = call.constructorReference.advancedResolve()
|
||||
if (resolveResult is GroovyMethodResult) {
|
||||
constraintCollector.add(MethodCallConstraint(null, resolveResult, method))
|
||||
constraintCollector.add(MethodCallConstraint(null, resolveResult, call))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -32,7 +32,7 @@ class InferredClosureParamsEnhancer : AbstractClosureParameterEnhancer() {
|
||||
val resolveResult = methodCall.advancedResolve() as? GroovyMethodResult ?: return null
|
||||
val virtualParameter = getVirtualParameter(resolveResult, closureBlock, virtualMethod) ?: return null
|
||||
val completeContextSubstitutor =
|
||||
virtualToActualSubstitutor.putAll(virtualSubstitutor(virtualMethod, resolveResult)) compose resolveResult.substitutor
|
||||
virtualToActualSubstitutor.putAll(virtualSubstitutor(virtualMethod, resolveResult, methodCall)) compose resolveResult.substitutor
|
||||
val anno = virtualParameter.modifierList.annotations.find { it.shortName == closureParamsShort } ?: return null
|
||||
val signatures = getSignatures(anno, completeContextSubstitutor, virtualMethod) ?: return null
|
||||
val parameters = closureBlock.allParameters
|
||||
@@ -59,13 +59,15 @@ class InferredClosureParamsEnhancer : AbstractClosureParameterEnhancer() {
|
||||
return processor.inferExpectedSignatures(virtualMethod, substitutor, options.toTypedArray())
|
||||
}
|
||||
|
||||
private fun virtualSubstitutor(virtualMethod: GrMethod, resolveResult: GroovyMethodResult): PsiSubstitutor {
|
||||
private fun virtualSubstitutor(virtualMethod: GrMethod,
|
||||
resolveResult: GroovyMethodResult,
|
||||
methodCall: GrCall): PsiSubstitutor {
|
||||
val originalMethod =
|
||||
resolveResult.candidate?.method?.takeIf { method -> method.parameters.all { it.name != null } } ?: return PsiSubstitutor.EMPTY
|
||||
val proxyMapping = originalMethod.parameters.map { it.name!! }.zip(virtualMethod.parameters).toMap()
|
||||
val session = CollectingGroovyInferenceSession(virtualMethod.typeParameters, virtualMethod, resolveResult.contextSubstitutor,
|
||||
proxyMapping)
|
||||
session.addConstraint(MethodCallConstraint(null, resolveResult, virtualMethod))
|
||||
session.addConstraint(MethodCallConstraint(null, resolveResult, methodCall))
|
||||
return session.inferSubst()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user