K1: don't filter Enum.entries in tower to report error later

After this commit we:
- preserve Enum.entries synthetic property in tower even in case the bound feature is OFF
- report an error on Enum.entries call in specific checker if the feature is OFF
- give this synthetic property lower priority, no matter feature ON or OFF

#KT-55251 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-01-19 11:49:11 +01:00
committed by Space Team
parent 793df6234e
commit 565adf3075
11 changed files with 77 additions and 16 deletions
@@ -73,7 +73,7 @@ private val DEFAULT_CALL_CHECKERS = listOf(
NewSchemeOfIntegerOperatorResolutionChecker, EnumEntryVsCompanionPriorityCallChecker, CompanionInParenthesesLHSCallChecker,
ResolutionToPrivateConstructorOfSealedClassChecker, EqualityCallChecker, UnsupportedUntilOperatorChecker,
BuilderInferenceAssignmentChecker, IncorrectCapturedApproximationCallChecker, CompanionIncorrectlyUnboundedWhenUsedAsLHSCallChecker,
CustomEnumEntriesMigrationCallChecker,
CustomEnumEntriesMigrationCallChecker, EnumEntriesUnsupportedChecker
)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.isSyntheticEnumEntries
object EnumEntriesUnsupportedChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val languageVersionSettings = context.languageVersionSettings
if (languageVersionSettings.supportsFeature(LanguageFeature.EnumEntries)) return
val propertyDescriptor = resolvedCall.resultingDescriptor as? PropertyDescriptor ?: return
if (propertyDescriptor.isSyntheticEnumEntries()) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
reportOn,
LanguageFeature.EnumEntries to languageVersionSettings
)
)
}
}
}
@@ -470,7 +470,7 @@ class PSICallResolver(
dispatchReceiver: ReceiverValueWithSmartCastInfo?,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): Collection<VariableDescriptor> {
val result = candidateInterceptor.interceptVariableCandidates(
return candidateInterceptor.interceptVariableCandidates(
initialResults,
this,
context,
@@ -481,14 +481,6 @@ class PSICallResolver(
dispatchReceiver,
extensionReceiver
)
if (name != StandardNames.ENUM_ENTRIES || languageVersionSettings.supportsFeature(LanguageFeature.EnumEntries)) {
return result
}
return result.filterNot {
it is PropertyDescriptor && it.isSynthesized &&
it.dispatchReceiverParameter == null && it.extensionReceiverParameter == null &&
(it.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.ENUM_CLASS
}
}
}