FE KT-47939 callable references to functional interface constructors
Allow callable references to Kotlin 'fun interface' constructors. Prohibit callable references to Java SAM interface constructors.
This commit is contained in:
committed by
TeamCityServer
parent
bfb6e73728
commit
1fd0dec5e7
+6
@@ -4333,4 +4333,10 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirJvmErrors.JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE) { firDiagnostic ->
|
||||
JavaSamInterfaceConstructorReferenceImpl(
|
||||
firDiagnostic as KtPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -3016,4 +3016,8 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = SpreadOnSignaturePolymorphicCallWarning::class
|
||||
}
|
||||
|
||||
abstract class JavaSamInterfaceConstructorReference : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = JavaSamInterfaceConstructorReference::class
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
@@ -3646,3 +3646,8 @@ internal class SpreadOnSignaturePolymorphicCallWarningImpl(
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.SpreadOnSignaturePolymorphicCallWarning(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
internal class JavaSamInterfaceConstructorReferenceImpl(
|
||||
override val firDiagnostic: KtPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.JavaSamInterfaceConstructorReference(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
|
||||
+12
-6
@@ -10919,6 +10919,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterfaceDisabled.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_after.kt")
|
||||
public void testFunInterfaceConstructorReferences_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_before.kt")
|
||||
public void testFunInterfaceConstructorReferences_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConversionOnReceiver.kt")
|
||||
public void testFunInterfaceConversionOnReceiver() throws Exception {
|
||||
@@ -10961,12 +10973,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("prohibitFunInterfaceConstructorReferences.kt")
|
||||
public void testProhibitFunInterfaceConstructorReferences() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/prohibitFunInterfaceConstructorReferences.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resolveFunInterfaceWithoutMainMethod.kt")
|
||||
public void testResolveFunInterfaceWithoutMainMethod() throws Exception {
|
||||
|
||||
+12
-6
@@ -10919,6 +10919,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterfaceDisabled.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_after.kt")
|
||||
public void testFunInterfaceConstructorReferences_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_before.kt")
|
||||
public void testFunInterfaceConstructorReferences_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConversionOnReceiver.kt")
|
||||
public void testFunInterfaceConversionOnReceiver() throws Exception {
|
||||
@@ -10961,12 +10973,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("prohibitFunInterfaceConstructorReferences.kt")
|
||||
public void testProhibitFunInterfaceConstructorReferences() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/prohibitFunInterfaceConstructorReferences.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resolveFunInterfaceWithoutMainMethod.kt")
|
||||
public void testResolveFunInterfaceWithoutMainMethod() throws Exception {
|
||||
|
||||
+1
@@ -183,5 +183,6 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
|
||||
ProhibitSpreadOnSignaturePolymorphicCall,
|
||||
PositioningStrategy.SPREAD_OPERATOR
|
||||
)
|
||||
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error<PsiElement>()
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -125,6 +125,7 @@ object FirJvmErrors {
|
||||
val SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC by error0<PsiElement>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
||||
val CONCURRENT_HASH_MAP_CONTAINS_OPERATOR by deprecationError0<PsiElement>(ProhibitConcurrentHashMapContains)
|
||||
val SPREAD_ON_SIGNATURE_POLYMORPHIC_CALL by deprecationError0<PsiElement>(ProhibitSpreadOnSignaturePolymorphicCall, SourceElementPositioningStrategies.SPREAD_OPERATOR)
|
||||
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error0<PsiElement>()
|
||||
|
||||
init {
|
||||
RootDiagnosticRendererFactory.registerFactory(FirJvmErrorsDefaultMessages)
|
||||
|
||||
+2
-2
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInterface
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJavaOrEnhancement
|
||||
import org.jetbrains.kotlin.fir.dispatchReceiverTypeOrNull
|
||||
import org.jetbrains.kotlin.fir.originalOrSelf
|
||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||
@@ -41,7 +42,6 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
* Note that, in case of multi-override, if any super member requires `override`, then the `override` keyword cannot be omitted.
|
||||
*/
|
||||
object FirJvmOverridesBackwardCompatibilityHelper : FirOverridesBackwardCompatibilityHelper {
|
||||
private val javaOrigin = setOf(FirDeclarationOrigin.Java, FirDeclarationOrigin.Enhancement)
|
||||
private val platformDependentAnnotation = ClassId.fromString("kotlin/internal/PlatformDependent")
|
||||
|
||||
override fun overrideCanBeOmitted(
|
||||
@@ -71,7 +71,7 @@ object FirJvmOverridesBackwardCompatibilityHelper : FirOverridesBackwardCompatib
|
||||
return true
|
||||
}
|
||||
|
||||
if (originalMember.origin !in javaOrigin) return false
|
||||
if (!originalMember.isJavaOrEnhancement) return false
|
||||
val containingClassName = originalMember.containingClass()?.classId?.asSingleFqName()?.toUnsafe() ?: return false
|
||||
// If the super class is mapped to a Kotlin built-in class, then we don't require `override` keyword.
|
||||
if (JavaToKotlinClassMap.mapKotlinToJava(containingClassName) != null) {
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ object JvmExpressionCheckers : ExpressionCheckers() {
|
||||
|
||||
override val qualifiedAccessExpressionCheckers: Set<FirQualifiedAccessExpressionChecker>
|
||||
get() = setOf(
|
||||
FirInterfaceDefaultMethodCallChecker
|
||||
FirInterfaceDefaultMethodCallChecker,
|
||||
FirJavaSamInterfaceConstructorReferenceChecker
|
||||
)
|
||||
|
||||
override val functionCallCheckers: Set<FirFunctionCallChecker>
|
||||
|
||||
+4
-5
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.StandardTypes
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirFunctionCallChecker
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJavaOrEnhancement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.argumentMapping
|
||||
import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol
|
||||
@@ -46,11 +46,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
* doesn't do anything to prevent this from happening.
|
||||
*/
|
||||
object FirJavaGenericVarianceViolationTypeChecker : FirFunctionCallChecker() {
|
||||
private val javaOrigin = setOf(FirDeclarationOrigin.Java, FirDeclarationOrigin.Enhancement)
|
||||
|
||||
override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val calleeFunction = expression.calleeReference.toResolvedCallableSymbol() as? FirFunctionSymbol<*> ?: return
|
||||
if (calleeFunction.originalOrSelf().origin !in javaOrigin) {
|
||||
if (!calleeFunction.originalOrSelf().isJavaOrEnhancement) {
|
||||
return
|
||||
}
|
||||
val argumentMapping = expression.argumentMapping ?: return
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.fir.analysis.jvm.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirQualifiedAccessExpressionChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFun
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJavaOrEnhancement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
|
||||
object FirJavaSamInterfaceConstructorReferenceChecker : FirQualifiedAccessExpressionChecker() {
|
||||
override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (expression !is FirCallableReferenceAccess) return
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitJavaSamInterfaceConstructorReference)) return
|
||||
|
||||
val reference = expression.calleeReference as? FirResolvedNamedReference ?: return
|
||||
val referredSymbol = reference.resolvedSymbol
|
||||
|
||||
if (referredSymbol is FirNamedFunctionSymbol &&
|
||||
referredSymbol.origin == FirDeclarationOrigin.SamConstructor
|
||||
) {
|
||||
val samClassSymbol = referredSymbol.resolvedReturnTypeRef.toRegularClassSymbol(context.session) ?: return
|
||||
if (samClassSymbol.isFun && samClassSymbol.isJavaOrEnhancement) {
|
||||
reporter.reportOn(reference.source, FirJvmErrors.JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
@@ -12,6 +13,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.FUN_INTERFACE_CON
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFun
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJavaOrEnhancement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.resolved
|
||||
@@ -20,15 +22,18 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
object FirFunInterfaceConstructorReferenceChecker : FirQualifiedAccessExpressionChecker() {
|
||||
override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (expression !is FirCallableReferenceAccess) return
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.AllowKotlinFunInterfaceConstructorReference)) return
|
||||
|
||||
val reference = expression.calleeReference.resolved ?: return
|
||||
val referredSymbol = reference.resolvedSymbol
|
||||
|
||||
if (referredSymbol is FirNamedFunctionSymbol &&
|
||||
referredSymbol.origin == FirDeclarationOrigin.SamConstructor &&
|
||||
referredSymbol.resolvedReturnTypeRef.toRegularClassSymbol(context.session)?.isFun == true
|
||||
referredSymbol.origin == FirDeclarationOrigin.SamConstructor
|
||||
) {
|
||||
reporter.reportOn(reference.source, FUN_INTERFACE_CONSTRUCTOR_REFERENCE, context)
|
||||
val samClassSymbol = referredSymbol.resolvedReturnTypeRef.toRegularClassSymbol(context.session) ?: return
|
||||
if (samClassSymbol.isFun && !samClassSymbol.isJavaOrEnhancement) {
|
||||
reporter.reportOn(reference.source, FUN_INTERFACE_CONSTRUCTOR_REFERENCE, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isJavaOrEnhancement
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
@@ -26,8 +27,6 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.SimpleDeprecationInfo
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
private val JAVA_ORIGINS = setOf(FirDeclarationOrigin.Java, FirDeclarationOrigin.Enhancement)
|
||||
|
||||
fun FirBasedSymbol<*>.getDeprecation(callSite: FirElement?): DeprecationInfo? {
|
||||
return when (this) {
|
||||
is FirPropertySymbol ->
|
||||
@@ -46,7 +45,7 @@ fun FirBasedSymbol<*>.getDeprecation(callSite: FirElement?): DeprecationInfo? {
|
||||
|
||||
fun FirAnnotationContainer.getDeprecationInfos(currentVersion: ApiVersion): DeprecationsPerUseSite {
|
||||
val deprecationByUseSite = mutableMapOf<AnnotationUseSiteTarget?, DeprecationInfo>()
|
||||
val fromJava = JAVA_ORIGINS.contains(this.safeAs<FirDeclaration>()?.origin)
|
||||
val fromJava = this.safeAs<FirDeclaration>()?.isJavaOrEnhancement == true
|
||||
annotations.extractDeprecationInfoPerUseSite(currentVersion, fromJava).toMap(deprecationByUseSite)
|
||||
|
||||
if (this is FirProperty) {
|
||||
|
||||
+9
-1
@@ -8,7 +8,11 @@ package org.jetbrains.kotlin.fir.declarations.utils
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.resolvedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -49,4 +53,8 @@ inline val FirDeclaration.isFromLibrary: Boolean
|
||||
inline val FirDeclaration.isSynthetic: Boolean
|
||||
get() = origin == FirDeclarationOrigin.Synthetic
|
||||
|
||||
inline val FirDeclaration.isJavaOrEnhancement: Boolean
|
||||
get() = origin == FirDeclarationOrigin.Java || origin == FirDeclarationOrigin.Enhancement
|
||||
inline val FirBasedSymbol<*>.isJavaOrEnhancement: Boolean
|
||||
get() = origin == FirDeclarationOrigin.Java || origin == FirDeclarationOrigin.Enhancement
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.jvm.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isCallableReference
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor
|
||||
|
||||
object SamInterfaceConstructorReferenceCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.ProhibitJavaSamInterfaceConstructorReference)) return
|
||||
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (resultingDescriptor !is SamConstructorDescriptor || !resolvedCall.call.isCallableReference()) return
|
||||
|
||||
if (!resultingDescriptor.baseDescriptorForSynthetic.isFun) {
|
||||
context.trace.report(
|
||||
ErrorsJvm.JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE.on(reportOn)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -223,6 +223,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
|
||||
MAP.put(TYPEOF_SUSPEND_TYPE, "Suspend functional types are not supported in typeOf");
|
||||
MAP.put(TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING);
|
||||
|
||||
MAP.put(JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE, "Java SAM interface constructor references are prohibited");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -202,6 +202,8 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory0<PsiElement> TYPEOF_SUSPEND_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
{
|
||||
|
||||
+5
-3
@@ -6,9 +6,10 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.platform
|
||||
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMapper
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.container.*
|
||||
import org.jetbrains.kotlin.container.PlatformExtensionsClashResolver
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.load.java.sam.JvmSamConversionOracle
|
||||
import org.jetbrains.kotlin.resolve.PlatformConfiguratorBase
|
||||
import org.jetbrains.kotlin.resolve.checkers.BigFunctionTypeAvailabilityChecker
|
||||
@@ -58,6 +59,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
||||
ApiVersionIsAtLeastArgumentsChecker,
|
||||
InconsistentOperatorFromJavaCallChecker,
|
||||
PolymorphicSignatureCallChecker,
|
||||
SamInterfaceConstructorReferenceCallChecker,
|
||||
),
|
||||
|
||||
additionalTypeCheckers = listOf(
|
||||
|
||||
+3
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isCallableReference
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
@@ -13,6 +14,8 @@ import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptor
|
||||
|
||||
object FunInterfaceConstructorReferenceChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.AllowKotlinFunInterfaceConstructorReference)) return
|
||||
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (resultingDescriptor !is SamConstructorDescriptor || !resolvedCall.call.isCallableReference()) return
|
||||
|
||||
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +AllowKotlinFunInterfaceConstructorReference +ProhibitJavaSamInterfaceConstructorReference
|
||||
|
||||
fun interface Foo {
|
||||
fun run()
|
||||
}
|
||||
|
||||
val x = ::Foo
|
||||
val y = Foo { }
|
||||
val z = ::<!JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE!>Runnable<!>
|
||||
+3
@@ -1,3 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: -AllowKotlinFunInterfaceConstructorReference -ProhibitJavaSamInterfaceConstructorReference
|
||||
|
||||
fun interface Foo {
|
||||
fun run()
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public val x: kotlin.reflect.KFunction1<() -> kotlin.Unit, Foo>
|
||||
public val y: Foo
|
||||
public val z: kotlin.reflect.KFunction1<() -> kotlin.Unit, java.lang.Runnable>
|
||||
|
||||
public fun interface Foo {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract fun run(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
fun interface Foo {
|
||||
fun run()
|
||||
}
|
||||
|
||||
val x = ::<!FUN_INTERFACE_CONSTRUCTOR_REFERENCE!>Foo<!>
|
||||
val y = Foo { }
|
||||
val z = ::<!FUN_INTERFACE_CONSTRUCTOR_REFERENCE!>Runnable<!>
|
||||
Generated
+12
-6
@@ -10925,6 +10925,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/basicFunInterfaceDisabled.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_after.kt")
|
||||
public void testFunInterfaceConstructorReferences_after() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_after.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConstructorReferences_before.kt")
|
||||
public void testFunInterfaceConstructorReferences_before() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/funInterfaceConstructorReferences_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("funInterfaceConversionOnReceiver.kt")
|
||||
public void testFunInterfaceConversionOnReceiver() throws Exception {
|
||||
@@ -10967,12 +10979,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("prohibitFunInterfaceConstructorReferences.kt")
|
||||
public void testProhibitFunInterfaceConstructorReferences() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/funInterface/prohibitFunInterfaceConstructorReferences.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resolveFunInterfaceWithoutMainMethod.kt")
|
||||
public void testResolveFunInterfaceWithoutMainMethod() throws Exception {
|
||||
|
||||
@@ -244,6 +244,7 @@ enum class LanguageFeature(
|
||||
ConsiderExtensionReceiverFromConstrainsInLambda(KOTLIN_1_7, kind = BUG_FIX), // KT-49832
|
||||
ProperInternalVisibilityCheckInImportingScope(KOTLIN_1_7, kind = BUG_FIX),
|
||||
InlineClassImplementationByDelegation(KOTLIN_1_7),
|
||||
AllowKotlinFunInterfaceConstructorReference(KOTLIN_1_7),
|
||||
|
||||
// 1.8
|
||||
|
||||
|
||||
Reference in New Issue
Block a user