Replace errors with warnings for type checker recursion on delegates

^KT-49477 Fixed
This commit is contained in:
Victor Petukhov
2021-10-29 17:26:03 +03:00
committed by teamcity
parent a4a2f71fca
commit 72a78eb423
36 changed files with 749 additions and 48 deletions
@@ -791,7 +791,7 @@ public interface Errors {
DiagnosticFactory1<PsiElement, String> NAME_SHADOWING = DiagnosticFactory1.create(WARNING, PositioningStrategies.FOR_REDECLARATION);
DiagnosticFactory0<PsiElement> ACCESSOR_PARAMETER_NAME_SHADOWING = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactory0.create(ERROR);
DiagnosticFactoryForDeprecation0<KtExpression> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = DiagnosticFactoryForDeprecation0.create(LanguageFeature.ForbidRecursiveDelegateExpressions);
// Checking call arguments
@@ -541,6 +541,21 @@ class DelegatedPropertyResolver(
return delegateType
}
private fun completeNotComputedDelegateType(trace: BindingTrace, traceToResolveDelegatedProperty: TemporaryBindingTrace) {
val ranIntoRecursionDiagnostic = traceToResolveDelegatedProperty.bindingContext.diagnostics.find {
it.factory == TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.errorFactory
|| it.factory == TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.warningFactory
}
if (ranIntoRecursionDiagnostic != null) {
trace.report(
TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(
languageVersionSettings,
ranIntoRecursionDiagnostic.psiElement as KtExpression
)
)
}
}
private fun resolveWithNewInference(
delegateExpression: KtExpression,
variableDescriptor: VariableDescriptorWithAccessors,
@@ -561,7 +576,7 @@ class DelegatedPropertyResolver(
)
var delegateType = delegateTypeInfo.type ?: run {
traceToResolveDelegatedProperty.commit()
completeNotComputedDelegateType(trace, traceToResolveDelegatedProperty)
return null
}
@@ -196,7 +196,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
context.trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, result);
}
catch (ReenteringLazyValueComputationException e) {
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.onError(expression));
result = TypeInfoFactoryKt.noTypeInfo(context);
}
@@ -211,7 +211,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
recordTypeInfo(expression, result);
}
catch (ReenteringLazyValueComputationException e) {
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.onError(expression));
return TypeInfoFactoryKt.noTypeInfo(context);
}
return result;