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:
committed by
Space Team
parent
793df6234e
commit
565adf3075
@@ -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(
|
||||
|
||||
+29
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
@@ -117,6 +118,10 @@ class CallableReferencesCandidateFactory(
|
||||
return createCallableReferenceCallCandidate(listOf(NotCallableMemberReference(kotlinCall, candidateDescriptor)))
|
||||
}
|
||||
|
||||
if (candidateDescriptor is PropertyDescriptor && candidateDescriptor.isSyntheticEnumEntries()) {
|
||||
diagnostics.add(LowerPriorityToPreserveCompatibility(needToReportWarning = false).asDiagnostic())
|
||||
}
|
||||
|
||||
diagnostics.addAll(towerCandidate.diagnostics)
|
||||
// todo smartcast on receiver diagnostic and CheckInstantiationOfAbstractClass
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstituto
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateFactory
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
+17
-3
@@ -6,6 +6,9 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.model
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
||||
import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl
|
||||
@@ -13,13 +16,14 @@ import org.jetbrains.kotlin.resolve.calls.components.candidate.SimpleErrorResolu
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.SimpleResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.error.ErrorScopeKind
|
||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
|
||||
class SimpleCandidateFactory(
|
||||
@@ -97,10 +101,15 @@ class SimpleCandidateFactory(
|
||||
)
|
||||
val extensionArgumentReceiver =
|
||||
createReceiverArgument(kotlinCall.getExplicitExtensionReceiver(explicitReceiverKind), extensionReceiver)
|
||||
val descriptor = towerCandidate.descriptor
|
||||
var diagnostics: List<KotlinCallDiagnostic> = towerCandidate.diagnostics
|
||||
if (descriptor is PropertyDescriptor && descriptor.isSyntheticEnumEntries()) {
|
||||
diagnostics = diagnostics + LowerPriorityToPreserveCompatibility(needToReportWarning = false).asDiagnostic()
|
||||
}
|
||||
|
||||
return createCandidate(
|
||||
towerCandidate.descriptor, explicitReceiverKind, dispatchArgumentReceiver,
|
||||
extensionArgumentReceiver, null, towerCandidate.diagnostics, knownSubstitutor = null
|
||||
descriptor, explicitReceiverKind, dispatchArgumentReceiver,
|
||||
extensionArgumentReceiver, extensionArgumentReceiverCandidates = null, diagnostics, knownSubstitutor = null
|
||||
)
|
||||
}
|
||||
|
||||
@@ -180,4 +189,9 @@ class SimpleCandidateFactory(
|
||||
extensionArgumentReceiverCandidates = null, initialDiagnostics = listOf(), knownSubstitutor = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun PropertyDescriptor.isSyntheticEnumEntries(): Boolean {
|
||||
return isSynthesized && dispatchReceiverParameter == null && extensionReceiverParameter == null &&
|
||||
(containingDeclaration as? ClassDescriptor)?.kind == ClassKind.ENUM_CLASS
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
$TESTDATA_DIR$/enumEntriesForJavaNotEnabled.kt
|
||||
-XXLanguage\:-EnumEntries
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
+10
-1
@@ -1,4 +1,13 @@
|
||||
compiler/testData/cli/jvm/enumEntriesForJavaNotEnabled.kt:4:49: error: unresolved reference: entries
|
||||
warning: ATTENTION!
|
||||
This build uses unsafe internal compiler arguments:
|
||||
|
||||
-XXLanguage:-EnumEntries
|
||||
|
||||
This mode is not recommended for production use,
|
||||
as no stability/compatibility guarantees are given on
|
||||
compiler or generated code. Use it at your own risk!
|
||||
|
||||
compiler/testData/cli/jvm/enumEntriesForJavaNotEnabled.kt:4:49: error: the feature "enum entries" is only available since language version 1.9
|
||||
val entries = java.util.concurrent.TimeUnit.entries
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
$TESTDATA_DIR$/enumEntriesNotEnabled.kt
|
||||
-XXLanguage\:-EnumEntries
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
|
||||
+10
-1
@@ -1,4 +1,13 @@
|
||||
compiler/testData/cli/jvm/enumEntriesNotEnabled.kt:7:26: error: unresolved reference: entries
|
||||
warning: ATTENTION!
|
||||
This build uses unsafe internal compiler arguments:
|
||||
|
||||
-XXLanguage:-EnumEntries
|
||||
|
||||
This mode is not recommended for production use,
|
||||
as no stability/compatibility guarantees are given on
|
||||
compiler or generated code. Use it at your own risk!
|
||||
|
||||
compiler/testData/cli/jvm/enumEntriesNotEnabled.kt:7:26: error: the feature "enum entries" is only available since language version 1.9
|
||||
val entries = MyEnum.entries
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -7,5 +7,5 @@ enum class Foo {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
Foo.<!UNRESOLVED_REFERENCE!>entries<!>
|
||||
Foo.<!OPT_IN_USAGE_ERROR, UNSUPPORTED_FEATURE!>entries<!>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user