Shift ReferencesToSyntheticJavaProperties feature release from 1.9 to 2.1

Other related tests:
- testGenericJavaProperty
- testFunInterfaceConstructorReference

Meta issue: KT-8575
Review: https://jetbrains.team/p/kt/reviews/9595

UnsupportedSyntheticCallableReferenceChecker only existed for K1,
because we wanted to release the feature for 1.9 and the feature should
have been working for K2 unconditionally. But since, we're postponing
the release until 2.1, we also need to port the checker from K1 to K2
This commit is contained in:
Nikita Bobko
2023-04-13 14:36:39 +02:00
committed by Space Team
parent 521a272acb
commit 5a96754aec
13 changed files with 63 additions and 44 deletions
@@ -23,6 +23,7 @@ object JvmExpressionCheckers : ExpressionCheckers() {
override val callableReferenceAccessCheckers: Set<FirCallableReferenceAccessChecker>
get() = setOf(
FirJavaShadowedFieldReferenceChecker,
FirUnsupportedSyntheticCallableReferenceChecker,
)
override val functionCallCheckers: Set<FirFunctionCallChecker>
@@ -0,0 +1,45 @@
/*
* 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.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.FirExpressionChecker
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.toResolvedCallableReference
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
/**
* This is K2 implementation.
* For K1 implementation see: [org.jetbrains.kotlin.resolve.jvm.checkers.UnsupportedSyntheticCallableReferenceChecker]
*/
object FirUnsupportedSyntheticCallableReferenceChecker : FirExpressionChecker<FirCallableReferenceAccess>() {
override fun check(expression: FirCallableReferenceAccess, context: CheckerContext, reporter: DiagnosticReporter) {
val parent = context.containingElements.let {
check(it.last() === expression)
it[it.lastIndex - 1]
}
// We allow resolution of top-level callable references to synthetic Java extension properties in the delegate position. See KT-47299
if (parent is FirProperty && parent.delegate === expression) return
if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.ReferencesToSyntheticJavaProperties) &&
expression.toResolvedCallableReference()?.resolvedSymbol is FirSyntheticPropertySymbol
) {
reporter.reportOn(
expression.calleeReference.source,
FirErrors.UNSUPPORTED_FEATURE,
LanguageFeature.ReferencesToSyntheticJavaProperties to context.session.languageVersionSettings,
context
)
}
}
}