diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index f80029dd8fd..f6a67da4a09 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -671,6 +671,19 @@ object DIAGNOSTICS_LIST : DiagnosticList() { val NEXT_NONE_APPLICABLE by error { parameter>>("candidates") } + val DELEGATE_SPECIAL_FUNCTION_MISSING by error { + parameter("expectedFunctionSignature") + parameter("delegateType") + parameter("description") + } + val DELEGATE_SPECIAL_FUNCTION_AMBIGUITY by error { + parameter("expectedFunctionSignature") + parameter>>("candidates") + } + val DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE by error { + parameter("expectedFunctionSignature") + parameter>>("candidates") + } } val TYPE_ALIAS by object : DiagnosticGroup("Type alias") { diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 52de915c19b..d7bef602682 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -393,6 +393,9 @@ object FirErrors { val NEXT_MISSING by error0() val HAS_NEXT_FUNCTION_NONE_APPLICABLE by error1>>() val NEXT_NONE_APPLICABLE by error1>>() + val DELEGATE_SPECIAL_FUNCTION_MISSING by error3() + val DELEGATE_SPECIAL_FUNCTION_AMBIGUITY by error2>>() + val DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE by error2>>() // Type alias val TOPLEVEL_TYPEALIASES_ONLY by error0() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt new file mode 100644 index 00000000000..8d78740ac29 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDelegatedPropertyChecker.kt @@ -0,0 +1,115 @@ +/* + * 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.checkers.declaration + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirFakeSourceElementKind +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn +import org.jetbrains.kotlin.fir.declarations.FirProperty +import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic +import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind +import org.jetbrains.kotlin.fir.expressions.FirFunctionCall +import org.jetbrains.kotlin.fir.expressions.arguments +import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError +import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol +import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType +import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.fir.types.render +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability +import org.jetbrains.kotlin.resolve.calls.tower.isSuccess + +object FirDelegatedPropertyChecker : FirPropertyChecker() { + override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) { + val delegate = declaration.delegate ?: return + val delegateType = delegate.typeRef.coneType + + if (delegateType is ConeKotlinErrorType) { + val delegateSource = delegate.source + // Implicit recursion type is not reported since the type ref does not have a real source. + if (delegateSource != null && (delegateType.diagnostic as? ConeSimpleDiagnostic)?.kind == DiagnosticKind.RecursionInImplicitTypes) { + // skip reporting other issues in this case + reporter.reportOn(delegateSource, FirErrors.RECURSION_IN_IMPLICIT_TYPES, context) + } + return + } + + class DelegatedPropertyAccessorVisitor(private val isGet: Boolean) : FirVisitorVoid() { + override fun visitElement(element: FirElement) = element.acceptChildren(this) + + override fun visitFunctionCall(functionCall: FirFunctionCall) { + val errorNamedReference = functionCall.calleeReference as? FirErrorNamedReference ?: return + if (errorNamedReference.source?.kind != FirFakeSourceElementKind.DelegatedPropertyAccessor) return + val expectedFunctionSignature = + (if (isGet) "getValue" else "setValue") + "(${functionCall.arguments.joinToString(", ") { it.typeRef.coneType.render() }})" + val delegateDescription = if (isGet) "delegate" else "delegate for var (read-write property)" + + fun reportInapplicableDiagnostics( + candidateApplicability: CandidateApplicability, + candidates: Collection> + ) { + if (candidateApplicability == CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER) { + reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, + expectedFunctionSignature, + delegateType, + delegateDescription, + context + ) + } else { + reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, + expectedFunctionSignature, + candidates, + context + ) + } + } + + when (val diagnostic = errorNamedReference.diagnostic) { + is ConeUnresolvedNameError -> { + reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING, + expectedFunctionSignature, + delegateType, + delegateDescription, + context + ) + } + is ConeAmbiguityError -> { + if (diagnostic.applicability.isSuccess) { + // Match is successful but there are too many matches! So we report DELEGATE_SPECIAL_FUNCTION_AMBIGUITY. + reporter.reportOn( + errorNamedReference.source, + FirErrors.DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, + expectedFunctionSignature, + diagnostic.candidates.map { it.symbol }, + context + ) + } else { + reportInapplicableDiagnostics(diagnostic.applicability, diagnostic.candidates.map { it.symbol }) + } + } + is ConeInapplicableCandidateError -> { + reportInapplicableDiagnostics(diagnostic.applicability, listOf(diagnostic.candidate.symbol)) + } + } + } + } + + declaration.getter?.body?.acceptChildren(DelegatedPropertyAccessorVisitor(true)) + declaration.setter?.body?.acceptChildren(DelegatedPropertyAccessorVisitor(false)) + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index 28440f05d57..29d2e3fc84a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -16,6 +16,8 @@ import org.jetbrains.kotlin.fir.declarations.FirErrorFunction import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.references.FirErrorNamedReference +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguityError +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.FirErrorTypeRef @@ -90,6 +92,14 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect if (source.elementType == KtNodeTypes.DESTRUCTURING_DECLARATION_ENTRY) { return } + + // Will be handled by [FirDelegatedPropertyChecker] + if (source.kind == FirFakeSourceElementKind.DelegatedPropertyAccessor && + (diagnostic is ConeUnresolvedNameError || diagnostic is ConeAmbiguityError || diagnostic is ConeInapplicableCandidateError) + ) { + return + } + if (source.kind == FirFakeSourceElementKind.ImplicitConstructor || source.kind == FirFakeSourceElementKind.DesugaredForLoop) { // See FirForLoopChecker return diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index 739a5984c82..e3b16d91d0d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -77,6 +77,9 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DATA_CLASS_VARARG import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DATA_CLASS_WITHOUT_PARAMETERS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATED_PROPERTY_INSIDE_INLINE_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATED_PROPERTY_IN_INTERFACE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATE_SPECIAL_FUNCTION_AMBIGUITY +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATION_IN_INTERFACE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.DEPRECATED_MODIFIER_PAIR @@ -846,13 +849,35 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { // Conventions map.put(NO_GET_METHOD, "No get method providing array access") map.put(NO_SET_METHOD, "No set method providing array access") + map.put( + DELEGATE_SPECIAL_FUNCTION_MISSING, + "Type ''{1}'' has no method ''{0}'' and thus it cannot serve as a {2}", + TO_STRING, + RENDER_TYPE, + TO_STRING + ) + map.put( + DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, + "Overload resolution ambiguity on method ''{0}'': {1}", + TO_STRING, + SYMBOLS + ) + map.put( + DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, + "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", + TO_STRING, + SYMBOLS + ) // Type alias map.put(TOPLEVEL_TYPEALIASES_ONLY, "Nested and local type aliases are not supported") // Returns map.put(RETURN_NOT_ALLOWED, "'return' is not allowed here") - map.put(RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY, "Returns are not allowed for functions with expression body. Use block body in '{...}'") + map.put( + RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY, + "Returns are not allowed for functions with expression body. Use block body in '{...}'" + ) // Extended checkers group map.put(REDUNDANT_VISIBILITY_MODIFIER, "Redundant visibility modifier") diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt index 66ade1ebbe1..80a77b4bd8d 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CommonDeclarationCheckers.kt @@ -50,7 +50,9 @@ object CommonDeclarationCheckers : DeclarationCheckers() { FirConstPropertyChecker, FirPropertyAccessorChecker, FirPropertyTypeParametersChecker, - FirPropertyAccessorChecker,FirInitializerTypeMismatchChecker + FirPropertyAccessorChecker, + FirInitializerTypeMismatchChecker, + FirDelegatedPropertyChecker, ) override val classCheckers: Set diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 31ce3fa274b..3cecf5920db 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -68,7 +68,7 @@ class CallAndReferenceGenerator( // val `x$delegate` = y // val x get() = `x$delegate`.getValue(this, ::x) // The reference here (like the rest of the accessor) has DefaultAccessor source kind. - val isForDelegate = callableReferenceAccess.source?.kind == FirFakeSourceElementKind.DefaultAccessor + val isForDelegate = callableReferenceAccess.source?.kind == FirFakeSourceElementKind.DelegatedPropertyAccessor val origin = if (isForDelegate) IrStatementOrigin.PROPERTY_REFERENCE_FOR_DELEGATE else null return callableReferenceAccess.convertWithOffsets { startOffset, endOffset -> when (symbol) { @@ -671,7 +671,7 @@ class CallAndReferenceGenerator( val typeParameters = fir.typeParameters.map { it.symbol.fir } if (typeParameters.size != type.typeArguments.size) return null val newTypeArguments = typeParameters.zip(type.typeArguments).map { (parameter, argument) -> - if (argument == ConeStarProjection){ + if (argument == ConeStarProjection) { parameter.bounds.first().coneType } else { argument @@ -685,7 +685,9 @@ class CallAndReferenceGenerator( // If the type of the argument is already an explicitly subtype of the type of the parameter, we don't need SAM conversion. if (argument.typeRef !is FirResolvedTypeRef || AbstractTypeChecker.isSubtypeOf( - session.inferenceComponents.ctx.newBaseTypeCheckerContext(errorTypesEqualToAnything = false, stubTypesEqualToAnything = true), + session.inferenceComponents.ctx.newBaseTypeCheckerContext( + errorTypesEqualToAnything = false, stubTypesEqualToAnything = true + ), argument.typeRef.coneType, parameter.returnTypeRef.coneType, isFromNullabilityConstraint = true diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 9844bb625fc..4d59757bac9 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -37,7 +37,6 @@ import org.jetbrains.kotlin.fir.types.builder.* import org.jetbrains.kotlin.fir.types.impl.* import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtQualifiedExpression import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.util.OperatorNameConventions @@ -314,7 +313,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( else -> null } val isMember = ownerSymbol != null - val fakeSource = delegateBuilder.source?.fakeElement(FirFakeSourceElementKind.DefaultAccessor) + val fakeSource = delegateBuilder.source?.fakeElement(FirFakeSourceElementKind.DelegatedPropertyAccessor) /* * If we have delegation with provide delegate then we generate call like @@ -458,6 +457,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( source = fakeSource explicitReceiver = delegateAccess() calleeReference = buildSimpleNamedReference { + source = fakeSource name = SET_VALUE } argumentList = buildArgumentList { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt index cb26513641c..b9e58f0b51d 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirSourceElement.kt @@ -37,6 +37,10 @@ sealed class FirFakeSourceElementKind : FirSourceElementKind() { // they have a fake source which refers to property object DefaultAccessor : FirFakeSourceElementKind() + // for delegated properties, getter & setter calls to the delegate + // they have a fake source which refers to the call that creates the delegate + object DelegatedPropertyAccessor : FirFakeSourceElementKind() + // for kt classes without implicit primary constructor one is generated // with a fake source which refers to containing class object ImplicitConstructor : FirFakeSourceElementKind() diff --git a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt index 49e4d905c33..0c5f2270f56 100644 --- a/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt +++ b/compiler/testData/diagnostics/tests/DeprecatedGetSetPropertyDelegateConvention.fir.kt @@ -33,8 +33,8 @@ operator fun CustomDelegate3.setValue(thisRef: Any?, prop: KProperty<*>, value: class Example { - var a by CustomDelegate() - val aval by CustomDelegate() + var a by CustomDelegate() + val aval by CustomDelegate() var b by OkDelegate() var c by CustomDelegate2() var d by CustomDelegate3() diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt index 9a21bc9308d..a2395d2332d 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.fir.kt @@ -29,9 +29,9 @@ private fun lazy(init: () -> T): kotlin.Lazy { } object DefaultHttpClientWithBy : HttpClient by client { - val client by lazy { HttpClientImpl() } + val client by lazy { HttpClientImpl() } } object DefaultFqHttpClient : HttpClient by DefaultFqHttpClient.client { val client = HttpClientImpl() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt index 87acfd28246..3d8c3592fb6 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt @@ -11,7 +11,7 @@ fun test() { const val a3 = 0 lateinit val a4 = 0 val a5 by Delegate() - val a6 by Delegate<T>() + val a6 by Delegate<T>() } class Delegate { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt index 10ffe8941be..331f065b8a4 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt @@ -11,7 +11,7 @@ fun test() { const val a3 = 0 lateinit val a4 = 0 val a5 by Delegate() - val a6 by Delegate<T>() + val a6 by Delegate<T>() } class Delegate { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt deleted file mode 100644 index 36688c7fa71..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -class A - -class D { - val c: Int by IncorrectThis() -} - -val cTopLevel: Int by IncorrectThis() - -class IncorrectThis { - fun get(t: Any?, p: KProperty<*>): Int { - return 1 - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.kt b/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.kt index 685501ec725..8cc0c863258 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/incompleteTypeInference.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt index 6e5716a408a..e2bada27d6b 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt @@ -12,8 +12,8 @@ class A(outer: Outer) { var b: String by foo(getMyProperty()) var r: String by foo(outer.getContainer().getMyProperty()) - var e: String by + foo(getMyProperty()) - var f: String by foo(getMyProperty()) - 1 + var e: String by + foo(getMyProperty()) + var f: String by foo(getMyProperty()) - 1 } fun foo(a: Any?) = MyProperty() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt index c27ce230540..69aba9c1ce7 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.fir.kt @@ -4,10 +4,10 @@ package foo import kotlin.reflect.KProperty open class A { - val B.w: Int by MyProperty() + val B.w: Int by MyProperty() } -val B.r: Int by MyProperty() +val B.r: Int by MyProperty() val A.e: Int by MyProperty() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt index 9ac6919c7db..e8a1dab052a 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt @@ -25,4 +25,4 @@ class C() { } var c1: Int by C() -var c2: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt index cfcbbdb2b9a..d24bc7c490f 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/manyIncompleteCandidates.fir.kt @@ -5,7 +5,7 @@ package test import first.* import second.* -val a12 by A() +val a12 by A() // FILE: first.kt package first diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt index 3e58fc32755..649c18f12a0 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.fir.kt @@ -4,8 +4,8 @@ package foo import kotlin.reflect.KProperty class A { - var a5: String by MyProperty1() - var b5: String by getMyProperty1() + var a5: String by MyProperty1() + var b5: String by getMyProperty1() } fun getMyProperty1() = MyProperty1() @@ -24,8 +24,8 @@ class MyProperty1 { // ----------------- class B { - var a5: String by MyProperty2() - var b5: String by getMyProperty2() + var a5: String by MyProperty2() + var b5: String by getMyProperty2() } fun getMyProperty2() = MyProperty2() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt deleted file mode 100644 index 596ae0070e3..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -//KT-4640 "Trace is erased after resolution completion" exception - -class ValueWrapper() -{ - var backingValue: Int = 0 - - fun getValue() = backingValue - fun setValue(v: Int) { backingValue = v } -} - -val foo by ValueWrapper() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.kt b/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.kt index d9f51272123..331dfb32b2e 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/kt4640.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL //KT-4640 "Trace is erased after resolution completion" exception class ValueWrapper() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt index 2433947dafe..1d318230d19 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/missedGetter.fir.kt @@ -1,3 +1,3 @@ -val a: Int by A() +val a: Int by A() class A diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt index f0e5d03622b..64651abf989 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/missedSetter.fir.kt @@ -2,7 +2,7 @@ import kotlin.reflect.KProperty -var a: Int by A() +var a: Int by A() class A { operator fun getValue(t: Any?, p: KProperty<*>): Int { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt deleted file mode 100644 index 9a306209f14..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -object T1 { - operator fun Int.provideDelegate(host: T1, p: Any): Long = 2 - operator fun Long.getValue(receiver: String, p: Any): Double = 1.0 - - val String.test1 by 1 - val test2 by 1 -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.kt index ceb77156dbc..b1eb81cc312 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER object T1 { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt index 130f6497beb..9643cdaf112 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/hostAndReceiver2.fir.kt @@ -10,5 +10,5 @@ object T2 { operator fun Foo.getValue(receiver: String, p: Any?): T = TODO() val String.test1: String by delegate() - val test2: String by delegate() + val test2: String by delegate() } diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt index 8b2936465f4..4aa4baa2c6e 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/provideDelegateOnFunctionalTypeWithThis.fir.kt @@ -13,7 +13,7 @@ fun wrong(arg: Wrong) {} class Wrong class Right { - val prop: () -> Unit by ::wrong + val prop: () -> Unit by ::wrong } fun box(): String { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt index db90e09363a..a18a23afc30 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.fir.kt @@ -4,12 +4,12 @@ import kotlin.reflect.KProperty -val a by a +val a by a val b by Delegate(b) -val c by d -val d by c +val c by d +val d by c class Delegate(i: Int) { operator fun getValue(t: Any?, p: KProperty<*>): Int { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt deleted file mode 100644 index 271810a415a..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE - -import kotlin.reflect.KProperty - -class D { - var c: Int by Delegate() -} - -var cTopLevel: Int by Delegate() - -class A - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): Int { - return 1 - } - operator fun setValue(t: A, p: KProperty<*>, i: Int) {} -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt index f529f06cc34..c81e0401fd0 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt deleted file mode 100644 index d8bdff29b9e..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE - -import kotlin.reflect.KProperty - -class A { - var a: Int by Delegate() -} - -var aTopLevel: Int by Delegate() - -class Delegate { - operator fun getValue(t: Nothing?, p: KProperty<*>): Int { - return 1 - } - operator fun setValue(t: Nothing?, p: KProperty<*>, a: Int) { - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.kt index 6c98a7c29e5..213772cb39f 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingNullableType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt deleted file mode 100644 index 00014ba19ea..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE - -import kotlin.reflect.KProperty - -class A { - var a: Int by Delegate() -} - -var aTopLevel: Int by Delegate() - -class Delegate { - fun getValue(t: Nothing, p: KProperty<*>): Int { - return 1 - } - fun setValue(t: Nothing, p: KProperty<*>, a: Int) { - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt index ef29a4d2e0e..6f559318844 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt deleted file mode 100644 index b9cac34cd3c..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -class A { - val c: Int by Delegate() -} - -class Delegate { - fun getValue(t: Int, p: KProperty<*>): Int { - return 1 - } - - fun getValue(t: String, p: KProperty<*>): Int { - return 1 - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.kt b/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.kt index f90603c7da2..63389f957bb 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/twoGetMethods.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt deleted file mode 100644 index 2025f032ec2..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -class A - -class B { - val b: Int by Delegate() -} - -val bTopLevel: Int by Delegate() - -class C { - val c: Int by Delegate() -} - -val cTopLevel: Int by Delegate() - -class Delegate { - operator fun getValue(t: T, p: KProperty<*>): Int { - return 1 - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.kt index f36212b8a54..cb3a9c63ae9 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetWithGeneric.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt deleted file mode 100644 index a54bd1c8435..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE - -import kotlin.reflect.KProperty - -class A { - var a: Int by Delegate() -} - -var aTopLevel: Int by Delegate() - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): Int { - return 1 - } - operator fun setValue(t: Any?, p: KProperty<*>, i: String) {} -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt index 20fd5336abe..a280a71a3a7 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt deleted file mode 100644 index c901f8c7115..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE - -import kotlin.reflect.KProperty - -class B { - val b: Int by Delegate() -} - -val bTopLevel: Int by Delegate() - -class A - -class Delegate { - fun getValue(t: A, p: KProperty<*>): Int { - return 1 - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.kt index 8fa5a3f4218..855ead8f6aa 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForThisGetParameter.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER // !WITH_NEW_INFERENCE diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt deleted file mode 100644 index 275e1445199..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.fir.kt +++ /dev/null @@ -1,15 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -class A { - val a: Int by Delegate() -} - -val aTopLevel: Int by Delegate() - -class Delegate { - fun getValue(t: Any?, p: KProperty<*>, a: Int): Int { - return a - } -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.kt index 8d4875fbee5..b212551321a 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInGet.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt deleted file mode 100644 index 747b8a09c8d..00000000000 --- a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KProperty - -class A { - var a: Int by Delegate() -} - -var aTopLevel: Int by Delegate() - -class Delegate { - operator fun getValue(t: Any?, p: KProperty<*>): Int { - return 1 - } - - operator fun setValue(t: Any?, p: KProperty<*>, a: Int, c: Int) {} -} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.kt b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.kt index 9190e4c95d8..c5db94fcbd8 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/wrongCountOfParametersInSet.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt deleted file mode 100644 index 14ab7e5b685..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// FILE: J.java - -import org.jetbrains.annotations.*; - -public class J { - - public interface DP { - String getValue(Object a, Object b); - String setValue(Object a, Object b, Object c); - } - - @NotNull - public static DP staticNN; - @Nullable - public static DP staticN; - public static DP staticJ; -} - -// FILE: k.kt - -var A by J.staticNN -var B by J.staticN -var C by J.staticJ diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt index 4120f26d029..a86fd732d95 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: J.java import org.jetbrains.annotations.*; diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt index 98914c36b4f..d5703b17233 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.fir.kt @@ -8,7 +8,7 @@ class Delegate { fun foo(): Int { val prop: Int by Delegate() - val prop2: Int by 123 + val prop2: Int by 123 val obj = object { fun v(): Int { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.fir.kt index 2d5dc57c918..44e1bf2e480 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.fir.kt @@ -17,7 +17,7 @@ fun case1() { } class B() { - val p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_MISSING expected + val p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE expected } class Delegate { @@ -42,7 +42,7 @@ fun case2() { } class B() { - var p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_MISSING expected + var p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE expected } class Delegate { diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.kt index 778014d510d..7f182460a76 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/building-the-overload-candidate-set-ocs/operator-call/p-4/neg/1.1.kt @@ -26,7 +26,7 @@ fun case1() { } class B() { - val p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_MISSING expected + val p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE expected } class Delegate { @@ -51,7 +51,7 @@ fun case2() { } class B() { - var p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_MISSING expected + var p: String by Delegate() // DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE expected } class Delegate { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt index 54485bc5769..9d99739c652 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt @@ -72,7 +72,7 @@ fun case_10(x: Boolean?) = when (val x where T: suspend () -> Unit, T: Boole // TESTCASE NUMBER: 11 fun case_11() { val x by lazy { 1 } - var x by lazy { 1 } + var x by lazy { 1 } } // TESTCASE NUMBER: 12 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 aff177f9356..5494b60fda3 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 @@ -1862,6 +1862,35 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.DELEGATE_SPECIAL_FUNCTION_MISSING) { firDiagnostic -> + DelegateSpecialFunctionMissingImpl( + firDiagnostic.a, + firSymbolBuilder.typeBuilder.buildKtType(firDiagnostic.b), + firDiagnostic.c, + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } + add(FirErrors.DELEGATE_SPECIAL_FUNCTION_AMBIGUITY) { firDiagnostic -> + DelegateSpecialFunctionAmbiguityImpl( + firDiagnostic.a, + firDiagnostic.b.map { abstractFirBasedSymbol -> + firSymbolBuilder.buildSymbol(abstractFirBasedSymbol.fir as FirDeclaration) + }, + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } + add(FirErrors.DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE) { firDiagnostic -> + DelegateSpecialFunctionNoneApplicableImpl( + firDiagnostic.a, + firDiagnostic.b.map { abstractFirBasedSymbol -> + firSymbolBuilder.buildSymbol(abstractFirBasedSymbol.fir as FirDeclaration) + }, + firDiagnostic as FirPsiDiagnostic<*>, + token, + ) + } add(FirErrors.TOPLEVEL_TYPEALIASES_ONLY) { firDiagnostic -> ToplevelTypealiasesOnlyImpl( firDiagnostic as FirPsiDiagnostic<*>, 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 dd4dc00dd6e..32fab085c1d 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 @@ -1305,6 +1305,25 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val candidates: List } + abstract class DelegateSpecialFunctionMissing : KtFirDiagnostic() { + override val diagnosticClass get() = DelegateSpecialFunctionMissing::class + abstract val expectedFunctionSignature: String + abstract val delegateType: KtType + abstract val description: String + } + + abstract class DelegateSpecialFunctionAmbiguity : KtFirDiagnostic() { + override val diagnosticClass get() = DelegateSpecialFunctionAmbiguity::class + abstract val expectedFunctionSignature: String + abstract val candidates: List + } + + abstract class DelegateSpecialFunctionNoneApplicable : KtFirDiagnostic() { + override val diagnosticClass get() = DelegateSpecialFunctionNoneApplicable::class + abstract val expectedFunctionSignature: String + abstract val candidates: List + } + abstract class ToplevelTypealiasesOnly : KtFirDiagnostic() { override val diagnosticClass get() = ToplevelTypealiasesOnly::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 9d8de501305..0336d673118 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 @@ -2116,6 +2116,34 @@ internal class NextNoneApplicableImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } +internal class DelegateSpecialFunctionMissingImpl( + override val expectedFunctionSignature: String, + override val delegateType: KtType, + override val description: String, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.DelegateSpecialFunctionMissing(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + +internal class DelegateSpecialFunctionAmbiguityImpl( + override val expectedFunctionSignature: String, + override val candidates: List, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.DelegateSpecialFunctionAmbiguity(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + +internal class DelegateSpecialFunctionNoneApplicableImpl( + override val expectedFunctionSignature: String, + override val candidates: List, + firDiagnostic: FirPsiDiagnostic<*>, + override val token: ValidityToken, +) : KtFirDiagnostic.DelegateSpecialFunctionNoneApplicable(), KtAbstractFirDiagnostic { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + internal class ToplevelTypealiasesOnlyImpl( firDiagnostic: FirPsiDiagnostic<*>, override val token: ValidityToken,