From f414a91c6628bea5b7a1b2a6a56e7e48f90c5517 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Wed, 1 Sep 2021 22:31:16 +0300 Subject: [PATCH] [FIR] Implement FirInterfaceDefaultMethodCallChecker Add diagnostics: INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET, INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET --- .../diagnostics/FirJvmDiagnosticsList.kt | 19 +- .../analysis/diagnostics/jvm/FirJvmErrors.kt | 4 + .../jvm/checkers/FirJvmAnnotationHelper.kt | 21 ++ .../fir/analysis/jvm/checkers/FirJvmHelper.kt | 13 + .../jvm/checkers/JvmExpressionCheckers.kt | 11 +- .../declaration/FirJvmDefaultChecker.kt | 23 +- .../FirRepeatableAnnotationChecker.kt | 12 +- .../FirInterfaceDefaultMethodCallChecker.kt | 74 ++++ .../diagnostics/FirJvmDefaultErrorMessages.kt | 15 + .../tests/j+k/defaultMethods.fir.kt | 60 ++-- .../defaultMethodsIndirectInheritance.fir.kt | 26 +- .../tests/j+k/defaultMethods_warning.fir.kt | 60 ++-- .../tests/j+k/traitDefaultCall.fir.kt | 42 --- .../diagnostics/tests/j+k/traitDefaultCall.kt | 1 + .../annotations/jvmDefault/jvmDefaults.fir.kt | 322 ------------------ .../annotations/jvmDefault/jvmDefaults.kt | 1 + .../diagnostics/KtFirDataClassConverters.kt | 30 ++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 20 ++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 35 ++ 19 files changed, 325 insertions(+), 464 deletions(-) create mode 100644 compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmHelper.kt delete mode 100644 compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt index 54ada1c3878..9ad230759b8 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt @@ -6,10 +6,10 @@ package org.jetbrains.kotlin.fir.checkers.generator.diagnostics import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.descriptors.Named +import org.jetbrains.kotlin.config.LanguageFeature.* import org.jetbrains.kotlin.fir.PrivateForInline -import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.* +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticList +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.PositioningStrategy import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -57,7 +57,9 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") { val OVERLOADS_ABSTRACT by error() val OVERLOADS_INTERFACE by error() val OVERLOADS_LOCAL by error() - val OVERLOADS_ANNOTATION_CLASS_CONSTRUCTOR by deprecationError(LanguageFeature.ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses) + val OVERLOADS_ANNOTATION_CLASS_CONSTRUCTOR by deprecationError( + ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses + ) val OVERLOADS_PRIVATE by warning() val DEPRECATED_JAVA_ANNOTATION by warning() { parameter("kotlinName") @@ -72,6 +74,7 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") { val SUPER_CALL_WITH_DEFAULT_PARAMETERS by error() { parameter("name") } + val INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER by error(PositioningStrategy.REFERENCE_BY_QUALIFIED) } val RECORDS by object : DiagnosticGroup("JVM Records") { @@ -129,5 +132,13 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") { parameter("message") } val JVM_SYNTHETIC_ON_DELEGATE by error() + val DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET by deprecationError( + DefaultMethodsCallFromJava6TargetError, + PositioningStrategy.REFERENCE_BY_QUALIFIED + ) + val INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET by deprecationError( + DefaultMethodsCallFromJava6TargetError, + PositioningStrategy.REFERENCE_BY_QUALIFIED + ) } } diff --git a/compiler/fir/checkers/checkers.jvm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/jvm/FirJvmErrors.kt b/compiler/fir/checkers/checkers.jvm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/jvm/FirJvmErrors.kt index b410ed2c92e..d02ce39d590 100644 --- a/compiler/fir/checkers/checkers.jvm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/jvm/FirJvmErrors.kt +++ b/compiler/fir/checkers/checkers.jvm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/jvm/FirJvmErrors.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.fir.analysis.diagnostics.jvm import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.config.LanguageFeature.DefaultMethodsCallFromJava6TargetError import org.jetbrains.kotlin.config.LanguageFeature.ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses import org.jetbrains.kotlin.fir.analysis.diagnostics.* import org.jetbrains.kotlin.fir.analysis.diagnostics.SourceElementPositioningStrategies @@ -59,6 +60,7 @@ object FirJvmErrors { // Super val SUPER_CALL_WITH_DEFAULT_PARAMETERS by error1() + val INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER by error0(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) // JVM Records val LOCAL_JVM_RECORD by error0() @@ -98,5 +100,7 @@ object FirJvmErrors { val INAPPLICABLE_JVM_FIELD by error1() val INAPPLICABLE_JVM_FIELD_WARNING by warning1() val JVM_SYNTHETIC_ON_DELEGATE by error0() + val DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET by deprecationError0(DefaultMethodsCallFromJava6TargetError, SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) + val INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET by deprecationError0(DefaultMethodsCallFromJava6TargetError, SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) } diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmAnnotationHelper.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmAnnotationHelper.kt index e69de29bb2d..e675ac6581f 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmAnnotationHelper.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmAnnotationHelper.kt @@ -0,0 +1,21 @@ +/* + * 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 + +import org.jetbrains.kotlin.config.JvmDefaultMode +import org.jetbrains.kotlin.fir.FirAnnotationContainer +import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.getAnnotationByFqName +import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol +import org.jetbrains.kotlin.name.JvmNames.JVM_DEFAULT_FQ_NAME + +fun FirBasedSymbol.isCompiledToJvmDefault(jvmDefaultMode: JvmDefaultMode): Boolean where D : FirAnnotationContainer, D : FirDeclaration { + // TODO: Fix support for all cases + if (getAnnotationByFqName(JVM_DEFAULT_FQ_NAME) != null) return true + + return jvmDefaultMode.forAllMethodsWithBody +} + diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmHelper.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmHelper.kt new file mode 100644 index 00000000000..9b30d9d460c --- /dev/null +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/FirJvmHelper.kt @@ -0,0 +1,13 @@ +/* + * 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 + +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.moduleData + +fun CheckerContext.isJvm6(): Boolean { + return session.moduleData.platform.componentPlatforms.any { it.targetName == "1.6" } +} \ No newline at end of file diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/JvmExpressionCheckers.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/JvmExpressionCheckers.kt index 6d62e496731..46837cb8395 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/JvmExpressionCheckers.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/JvmExpressionCheckers.kt @@ -8,12 +8,15 @@ package org.jetbrains.kotlin.fir.analysis.jvm.checkers import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirAnnotationCallChecker import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirFunctionCallChecker -import org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression.FirDeprecatedJavaAnnotationsChecker -import org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression.FirJavaGenericVarianceViolationTypeChecker -import org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression.FirJvmPackageNameAnnotationsChecker -import org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression.FirSuperCallWithDefaultsChecker +import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirQualifiedAccessExpressionChecker +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression.* object JvmExpressionCheckers : ExpressionCheckers() { + override val qualifiedAccessExpressionCheckers: Set + get() = setOf( + FirInterfaceDefaultMethodCallChecker + ) + override val functionCallCheckers: Set get() = setOf( FirJavaGenericVarianceViolationTypeChecker, diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmDefaultChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmDefaultChecker.kt index 0d17ace1d94..b18c645406e 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmDefaultChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmDefaultChecker.kt @@ -14,39 +14,38 @@ import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.isCompiledToJvmDefault +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.isJvm6 import org.jetbrains.kotlin.fir.containingClass import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isInterface import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.java.jvmDefaultModeState -import org.jetbrains.kotlin.fir.moduleData import org.jetbrains.kotlin.fir.resolve.toFirRegularClass import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenFunctions import org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirIntersectionCallableSymbol -import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.JvmNames.JVM_DEFAULT_FQ_NAME +import org.jetbrains.kotlin.name.JvmNames.JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME object FirJvmDefaultChecker : FirBasicDeclarationChecker() { - private val JVM_DEFAULT_FQ_NAME = FqName("kotlin.jvm.JvmDefault") - private val JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME = FqName("kotlin.jvm.JvmDefaultWithoutCompatibility") - override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { val jvmDefaultMode = context.session.jvmDefaultModeState var defaultAnnotation: FirAnnotationCall? = null val containingDeclaration = context.findClosest() if (declaration is FirAnnotatedDeclaration) { - val isJvm16 = context.session.moduleData.platform.componentPlatforms.any { it.targetName == "1.6" } - defaultAnnotation = declaration.getAnnotationByFqName(JVM_DEFAULT_FQ_NAME) + val isJvm6 = context.isJvm6() + defaultAnnotation = declaration.getAnnotationByClassId(JVM_DEFAULT_CLASS_ID) if (defaultAnnotation != null) { if (containingDeclaration !is FirClass || !containingDeclaration.isInterface) { reporter.reportOn(defaultAnnotation.source, FirJvmErrors.JVM_DEFAULT_NOT_IN_INTERFACE, context) return - } else if (isJvm16) { + } else if (isJvm6) { reporter.reportOn(defaultAnnotation.source, FirJvmErrors.JVM_DEFAULT_IN_JVM6_TARGET, "JvmDefault", context) return } else if (!jvmDefaultMode.isEnabled) { @@ -56,7 +55,7 @@ object FirJvmDefaultChecker : FirBasicDeclarationChecker() { } else { val annotation = declaration.getAnnotationByFqName(JVM_DEFAULT_NO_COMPATIBILITY_FQ_NAME) if (annotation != null) { - if (isJvm16) { + if (isJvm6) { reporter.reportOn( annotation.source, FirJvmErrors.JVM_DEFAULT_IN_JVM6_TARGET, @@ -176,10 +175,4 @@ object FirJvmDefaultChecker : FirBasicDeclarationChecker() { // TODO: Fix support for all cases return isCompiledToJvmDefault(jvmDefaultMode) } - - fun FirCallableSymbol<*>.isCompiledToJvmDefault(): Boolean { - // TODO: Fix support for all cases - if (getAnnotationByFqName(JVM_DEFAULT_FQ_NAME) != null) return true - return false - } } \ No newline at end of file diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt index cb1decd727d..dab097b3c6f 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt @@ -13,10 +13,14 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirAnnotatedDeclar import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.isJvm6 import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.FirClassReferenceExpression +import org.jetbrains.kotlin.fir.expressions.FirGetClassCall +import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.languageVersionSettings -import org.jetbrains.kotlin.fir.moduleData import org.jetbrains.kotlin.fir.resolve.fqName import org.jetbrains.kotlin.fir.resolve.symbolProvider import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol @@ -41,14 +45,14 @@ object FirRepeatableAnnotationChecker : FirAnnotatedDeclarationChecker() { val classId = annotation.classId ?: continue val annotationClassId = annotation.toAnnotationClassId() ?: continue if (annotationClassId.isLocal) continue - val annotationClass = session.symbolProvider.getClassLikeSymbolByFqName(annotationClassId) ?: continue + val annotationClass = session.symbolProvider.getClassLikeSymbolByClassId(annotationClassId) ?: continue // TODO: consider REPEATED_ANNOTATION ? if (fqName in annotationsSet && annotationClass.isRepeatableAnnotation(session) && annotationClass.getAnnotationRetention() != AnnotationRetention.SOURCE ) { - if (session.moduleData.platform.componentPlatforms.any { it.targetName == "1.6" }) { + if (context.isJvm6()) { reporter.reportOn(annotation.source, FirJvmErrors.REPEATED_ANNOTATION_TARGET6, context) } else if (session.languageVersionSettings.supportsFeature(LanguageFeature.RepeatableAnnotations)) { // It's not allowed to have both a repeated annotation (applied more than once) and its container diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/expression/FirInterfaceDefaultMethodCallChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/expression/FirInterfaceDefaultMethodCallChecker.kt index e69de29bb2d..5a305382cc1 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/expression/FirInterfaceDefaultMethodCallChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/expression/FirInterfaceDefaultMethodCallChecker.kt @@ -0,0 +1,74 @@ +/* + * 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.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest +import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirQualifiedAccessExpressionChecker +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.isCompiledToJvmDefault +import org.jetbrains.kotlin.fir.analysis.jvm.checkers.isJvm6 +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.utils.isInterface +import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression +import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol +import org.jetbrains.kotlin.fir.java.jvmDefaultModeState +import org.jetbrains.kotlin.fir.references.FirSuperReference +import org.jetbrains.kotlin.fir.resolve.symbolProvider +import org.jetbrains.kotlin.fir.symbols.impl.ANONYMOUS_CLASS_ID +import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.symbols.impl.isStatic +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +object FirInterfaceDefaultMethodCallChecker : FirQualifiedAccessExpressionChecker() { + override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) { + val supportsDefaults = !context.isJvm6() + + val symbol = expression.calleeReference.toResolvedCallableSymbol() + val classId = symbol?.callableId?.classId ?: return + if (classId.isLocal) return + val typeSymbol = context.session.symbolProvider.getClassLikeSymbolByFqName(classId) as? FirRegularClassSymbol ?: return + + if (!supportsDefaults && + symbol.isStatic && + typeSymbol.isInterface && + typeSymbol.origin == FirDeclarationOrigin.Java + ) { + reporter.reportOn(expression.source, FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET, context) + } + + if (expression.explicitReceiver.safeAs() + ?.calleeReference.safeAs() == null + ) { + return + } + + val containingDeclaration = context.findClosest() ?: return + + val jvmDefaultMode = context.session.jvmDefaultModeState + if (typeSymbol.isInterface && (typeSymbol.origin == FirDeclarationOrigin.Java || symbol.isCompiledToJvmDefault(jvmDefaultMode))) { + if (containingDeclaration.isInterface) { + val containingMember = context.findContainingMember()?.symbol + if (containingMember?.isCompiledToJvmDefault(jvmDefaultMode) == false) { + reporter.reportOn(expression.source, FirJvmErrors.INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, context) + return + } + } + + if (!supportsDefaults) { + reporter.reportOn(expression.source, FirJvmErrors.DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET, context) + } + } + } + + private fun CheckerContext.findContainingMember(): FirCallableDeclaration? { + return findClosest { + (it is FirSimpleFunction && it.symbol.callableId.classId != ANONYMOUS_CLASS_ID) || it is FirProperty + } + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/diagnostics/FirJvmDefaultErrorMessages.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/diagnostics/FirJvmDefaultErrorMessages.kt index 7920cd72c7f..146252a2773 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/diagnostics/FirJvmDefaultErrorMessages.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/diagnostics/FirJvmDefaultErrorMessages.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDefaultErrorMessages import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.RENDER_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.TO_STRING import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.CONFLICTING_JVM_DECLARATIONS +import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.DELEGATION_BY_IN_JVM_RECORD import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.DEPRECATED_JAVA_ANNOTATION import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.ENUM_JVM_RECORD @@ -25,6 +26,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INAPPLICAB import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INAPPLICABLE_JVM_FIELD import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INAPPLICABLE_JVM_FIELD_WARNING import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INNER_JVM_RECORD +import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER +import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_DECLARATION import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_JVM6_TARGET @@ -204,6 +207,18 @@ object FirJvmDefaultErrorMessages { INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, "Interfaces can call default methods via super only within @JvmDefault members. Please annotate the containing interface member with @JvmDefault" ) + map.put( + DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET, + "Super calls to Java default methods are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'" + ) + map.put( + INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET, + "Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'" + ) + map.put( + INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, + "Interfaces can call default methods via super only within @JvmDefault members. Please annotate the containing interface member with @JvmDefault" + ) } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt index fb89c234e71..47a65f32951 100644 --- a/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethods.fir.kt @@ -20,23 +20,23 @@ import JavaInterface.testStatic interface KotlinInterface : JavaInterface { fun fooo() { - testStatic() - super.test() + testStatic() + super.test() object { fun run () { - super@KotlinInterface.test() + super@KotlinInterface.test() } } } val propertyy: String get() { - super.test() + super.test() object { fun run () { - super@KotlinInterface.test() + super@KotlinInterface.test() } } return "" @@ -49,23 +49,23 @@ interface KotlinInterface : JavaInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterface { fun foooo() { - testStatic() - super.test() + testStatic() + super.test() object { fun run () { - super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.test() } } } val propertyyy: String get() { - super.test() + super.test() object { fun run () { - super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.test() } } return "" @@ -74,25 +74,25 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface { open class KotlinClass : JavaInterface { fun foo() { - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() object { fun run () { - super@KotlinClass.test() + super@KotlinClass.test() } } } val property: String get() { - super.test() - super.testOverride() + super.test() + super.testOverride() object { fun run () { - super@KotlinClass.test() + super@KotlinClass.test() } } return "" @@ -101,25 +101,25 @@ open class KotlinClass : JavaInterface { class KotlinClassIndirectInheritance : KotlinClass() { fun foo2(){ - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.test() } } } val property2: String get() { - super.test() - super.testOverride() + super.test() + super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.test() } } return "" @@ -128,25 +128,25 @@ class KotlinClassIndirectInheritance : KotlinClass() { class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { fun foo() { - testStatic() - super.test() + testStatic() + super.test() super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.test() } } } val property: String get() { - super.test() + super.test() super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.test() } } return "" @@ -154,7 +154,7 @@ class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { } fun test() { - JavaInterface.testStatic() + JavaInterface.testStatic() KotlinClass().foo() KotlinClass().property KotlinClassIndirectInheritance2().foo() diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt index 45be799023e..1ecaa9ebc83 100644 --- a/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethodsIndirectInheritance.fir.kt @@ -25,8 +25,8 @@ import JavaInterface.testStatic interface KotlinInterface : JavaInterface { fun fooo() { - testStatic() - super.test() + testStatic() + super.test() test() testOverride() } @@ -38,8 +38,8 @@ interface KotlinInterface : JavaInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterface { fun foooo() { - testStatic() - super.test() + testStatic() + super.test() testOverride() super.testOverride() } @@ -47,30 +47,30 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface { open class KotlinClass : JavaInterface { fun foo(){ - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() } } class KotlinClassIndirectInheritance : KotlinClass() { fun foo2(){ - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() } } class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { fun foo(){ - testStatic() - super.test() + testStatic() + super.test() super.testOverride() } } fun test() { - JavaInterface.testStatic() + JavaInterface.testStatic() KotlinClass().foo() KotlinClassIndirectInheritance2().foo() diff --git a/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt b/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt index 00e24b30071..f8223874863 100644 --- a/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/defaultMethods_warning.fir.kt @@ -22,23 +22,23 @@ import JavaInterface.testStatic interface KotlinInterface : JavaInterface { fun fooo() { - testStatic() - super.test() + testStatic() + super.test() object { fun run () { - super@KotlinInterface.test() + super@KotlinInterface.test() } } } val propertyy: String get() { - super.test() + super.test() object { fun run () { - super@KotlinInterface.test() + super@KotlinInterface.test() } } return "" @@ -51,23 +51,23 @@ interface KotlinInterface : JavaInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterface { fun foooo() { - testStatic() - super.test() + testStatic() + super.test() object { fun run () { - super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.test() } } } val propertyyy: String get() { - super.test() + super.test() object { fun run () { - super@KotlinInterfaceIndirectInheritance.test() + super@KotlinInterfaceIndirectInheritance.test() } } return "" @@ -76,25 +76,25 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface { open class KotlinClass : JavaInterface { fun foo(){ - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() object { fun run () { - super@KotlinClass.test() + super@KotlinClass.test() } } } val property: String get() { - super.test() - super.testOverride() + super.test() + super.testOverride() object { fun run () { - super@KotlinClass.test() + super@KotlinClass.test() } } return "" @@ -103,25 +103,25 @@ open class KotlinClass : JavaInterface { class KotlinClassIndirectInheritance : KotlinClass() { fun foo2(){ - testStatic() - super.test() - super.testOverride() + testStatic() + super.test() + super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.test() } } } val property2: String get() { - super.test() - super.testOverride() + super.test() + super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance.test() + super@KotlinClassIndirectInheritance.test() } } return "" @@ -130,25 +130,25 @@ class KotlinClassIndirectInheritance : KotlinClass() { class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { fun foo(){ - testStatic() - super.test() + testStatic() + super.test() super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.test() } } } val property: String get() { - super.test() + super.test() super.testOverride() object { fun run () { - super@KotlinClassIndirectInheritance2.test() + super@KotlinClassIndirectInheritance2.test() } } return "" @@ -156,7 +156,7 @@ class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { } fun test() { - JavaInterface.testStatic() + JavaInterface.testStatic() KotlinClass().foo() KotlinClass().property KotlinClassIndirectInheritance2().foo() diff --git a/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt b/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt deleted file mode 100644 index 0dc00cfd49a..00000000000 --- a/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.fir.kt +++ /dev/null @@ -1,42 +0,0 @@ -// !JVM_TARGET: 1.6 -// FILE: Test.java -public interface Test { - default String test() { - return "123"; - } -} - -// FILE: test.kt -interface KTrait : Test { - fun ktest() { - super.test() - - test() - } -} - - -interface KTrait2 : KTrait { - fun ktest2() { - super.test() - - test() - } -} - -class A : KTrait { - fun a() { - super.test() - - test() - } -} - - -class A2 : KTrait2 { - fun a() { - super.test() - - test() - } -} diff --git a/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.kt b/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.kt index ebe5049641c..d036217cdd9 100644 --- a/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.kt +++ b/compiler/testData/diagnostics/tests/j+k/traitDefaultCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !JVM_TARGET: 1.6 // FILE: Test.java public interface Test { diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt deleted file mode 100644 index ad53ea01de2..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.fir.kt +++ /dev/null @@ -1,322 +0,0 @@ -// !JVM_DEFAULT_MODE: enable -// !JVM_TARGET: 1.8 - -public interface KInterface { - @JvmDefault - fun test(): String { - return "OK"; - } - - @JvmDefault - val property: String - get() = "OK" - - - fun testNonDefault(): String { - return "OK"; - } - - val propertyNonDefault: String - get() = "OK" -} - -// FILE: 1.kt - -interface KotlinInterface : KInterface { - @JvmDefault - fun fooo() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterface.test() - super@KotlinInterface.property - - super@KotlinInterface.testNonDefault() - super@KotlinInterface.propertyNonDefault - } - } - } - - @JvmDefault - val propertyy: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterface.test() - super@KotlinInterface.property - - super@KotlinInterface.testNonDefault() - super@KotlinInterface.propertyNonDefault - } - } - return "" - } - - fun foooNonDefault() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterface.test() - super@KotlinInterface.property - - super@KotlinInterface.testNonDefault() - super@KotlinInterface.propertyNonDefault - } - } - } - - val propertyyNonDefault: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterface.test() - super@KotlinInterface.property - - super@KotlinInterface.testNonDefault() - super@KotlinInterface.propertyNonDefault - } - } - return "" - } - - -} - -interface KotlinInterfaceIndirectInheritance : KotlinInterface { - @JvmDefault - fun foooo() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterfaceIndirectInheritance.test() - super@KotlinInterfaceIndirectInheritance.property - - super@KotlinInterfaceIndirectInheritance.testNonDefault() - super@KotlinInterfaceIndirectInheritance.propertyNonDefault - } - } - } - - @JvmDefault - val propertyyy: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterfaceIndirectInheritance.test() - super@KotlinInterfaceIndirectInheritance.property - - super@KotlinInterfaceIndirectInheritance.testNonDefault() - super@KotlinInterfaceIndirectInheritance.propertyNonDefault - } - } - return "" - } - - fun fooooNonDefault() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterfaceIndirectInheritance.test() - super@KotlinInterfaceIndirectInheritance.property - - super@KotlinInterfaceIndirectInheritance.testNonDefault() - super@KotlinInterfaceIndirectInheritance.propertyNonDefault - } - } - } - - val propertyyyNonDefault: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinInterfaceIndirectInheritance.test() - super@KotlinInterfaceIndirectInheritance.property - - super@KotlinInterfaceIndirectInheritance.testNonDefault() - super@KotlinInterfaceIndirectInheritance.propertyNonDefault - } - } - return "" - } -} - -open class KotlinClass : KInterface { - fun foo() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClass.test() - super@KotlinClass.property - - super@KotlinClass.testNonDefault() - super@KotlinClass.propertyNonDefault - } - } - } - - val xproperty: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClass.test() - super@KotlinClass.property - - super@KotlinClass.testNonDefault() - super@KotlinClass.propertyNonDefault - } - } - - return "" - } -} - -class KotlinClassIndirectInheritance : KotlinClass() { - fun foo2() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClassIndirectInheritance.test() - super@KotlinClassIndirectInheritance.property - - super@KotlinClassIndirectInheritance.testNonDefault() - super@KotlinClassIndirectInheritance.propertyNonDefault - } - } - - } - - val property2: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClassIndirectInheritance.test() - super@KotlinClassIndirectInheritance.property - - super@KotlinClassIndirectInheritance.testNonDefault() - super@KotlinClassIndirectInheritance.propertyNonDefault - } - } - return "" - } -} - -class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { - fun foo() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClassIndirectInheritance2.test() - super@KotlinClassIndirectInheritance2.property - - super@KotlinClassIndirectInheritance2.testNonDefault() - super@KotlinClassIndirectInheritance2.propertyNonDefault - } - } - } - - val xproperty: String - get() { - super.test() - super.property - - super.testNonDefault() - super.propertyNonDefault - - object { - fun run () { - super@KotlinClassIndirectInheritance2.test() - super@KotlinClassIndirectInheritance2.property - - super@KotlinClassIndirectInheritance2.testNonDefault() - super@KotlinClassIndirectInheritance2.propertyNonDefault - } - } - return "" - } -} - -fun test() { - KotlinClass().test() - KotlinClass().property - KotlinClass().propertyNonDefault - KotlinClassIndirectInheritance2().test() - KotlinClassIndirectInheritance2().testNonDefault() - KotlinClassIndirectInheritance2().propertyyy - KotlinClassIndirectInheritance2().propertyyyNonDefault - - KotlinClass().test() - KotlinClass().testNonDefault() - KotlinClass().property - KotlinClass().propertyNonDefault -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt index 22820b64cd5..668f15eed33 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !JVM_DEFAULT_MODE: enable // !JVM_TARGET: 1.8 diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index 354742d35a0..9fa99d1197c 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -361,6 +361,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirJvmErrors.INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER) { firDiagnostic -> + InterfaceCantCallDefaultMethodViaSuperImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } add(FirErrors.NOT_A_SUPERTYPE) { firDiagnostic -> NotASupertypeImpl( firDiagnostic as FirPsiDiagnostic, @@ -3820,4 +3826,28 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirJvmErrors.DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET.errorFactory) { firDiagnostic -> + DefaultMethodCallFromJava6TargetErrorImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } + add(FirJvmErrors.DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET.warningFactory) { firDiagnostic -> + DefaultMethodCallFromJava6TargetWarningImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } + add(FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET.errorFactory) { firDiagnostic -> + InterfaceStaticMethodCallFromJava6TargetErrorImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } + add(FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET.warningFactory) { firDiagnostic -> + InterfaceStaticMethodCallFromJava6TargetWarningImpl( + firDiagnostic as FirPsiDiagnostic, + token, + ) + } } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index d1f9dcf3837..1d5b1708d33 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -281,6 +281,10 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val name: String } + abstract class InterfaceCantCallDefaultMethodViaSuper : KtFirDiagnostic() { + override val diagnosticClass get() = InterfaceCantCallDefaultMethodViaSuper::class + } + abstract class NotASupertype : KtFirDiagnostic() { override val diagnosticClass get() = NotASupertype::class } @@ -2656,4 +2660,20 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = JvmSyntheticOnDelegate::class } + abstract class DefaultMethodCallFromJava6TargetError : KtFirDiagnostic() { + override val diagnosticClass get() = DefaultMethodCallFromJava6TargetError::class + } + + abstract class DefaultMethodCallFromJava6TargetWarning : KtFirDiagnostic() { + override val diagnosticClass get() = DefaultMethodCallFromJava6TargetWarning::class + } + + abstract class InterfaceStaticMethodCallFromJava6TargetError : KtFirDiagnostic() { + override val diagnosticClass get() = InterfaceStaticMethodCallFromJava6TargetError::class + } + + abstract class InterfaceStaticMethodCallFromJava6TargetWarning : KtFirDiagnostic() { + override val diagnosticClass get() = InterfaceStaticMethodCallFromJava6TargetWarning::class + } + } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 059824efd8c..bfbdabce7fa 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -417,6 +417,13 @@ internal class SuperCallWithDefaultParametersImpl( override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) } +internal class InterfaceCantCallDefaultMethodViaSuperImpl( + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.InterfaceCantCallDefaultMethodViaSuper(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} + internal class NotASupertypeImpl( firDiagnostic: FirPsiDiagnostic, override val token: ValidityToken, @@ -4319,3 +4326,31 @@ internal class JvmSyntheticOnDelegateImpl( override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) } +internal class DefaultMethodCallFromJava6TargetErrorImpl( + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.DefaultMethodCallFromJava6TargetError(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} + +internal class DefaultMethodCallFromJava6TargetWarningImpl( + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.DefaultMethodCallFromJava6TargetWarning(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} + +internal class InterfaceStaticMethodCallFromJava6TargetErrorImpl( + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.InterfaceStaticMethodCallFromJava6TargetError(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} + +internal class InterfaceStaticMethodCallFromJava6TargetWarningImpl( + firDiagnostic: FirPsiDiagnostic, + override val token: ValidityToken, +) : KtFirDiagnostic.InterfaceStaticMethodCallFromJava6TargetWarning(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic) +} +