[FIR] Assign the property source to accessors from delegates The change in `FirWebCommonExternalPropertyAccessorChecker` is backed by `compiler/testData/diagnostics/testsWithJsStdLib/native/delegation.kt`. In `signatureClashVariables.kt`, `CONFLICTING_KLIB_SIGNATURES_ERROR` moved to the whole property, but `DeduplicatingDiagnosticReporter` avoids duplicates. `anonymousDelegate.fir.txt` disappears, because `setDelegate` moves down a but in `AnonymousDelegateKt`, making the dump identical to `.txt`. ^KT-72295 Fixed
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/RawFirNonLocalDeclarationBuilder.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/RawFirNonLocalDeclarationBuilder.kt index a76172b..f7cb0eb 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/RawFirNonLocalDeclarationBuilder.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/lazy/resolve/RawFirNonLocalDeclarationBuilder.kt
@@ -42,9 +42,6 @@ private val declarationToBuild: KtElement, private val functionsToRebind: Set<FirFunction>, ) : PsiRawFirBuilder(session, baseScopeProvider, bodyBuildingMode = BodyBuildingMode.NORMAL) { - override val KtProperty.sourceForDelegatedPropertyAccessors: KtSourceElement? - get() = this.toFirSourceElement() - companion object { fun buildWithFunctionSymbolRebind( session: FirSession,
diff --git a/compiler/fir/checkers/checkers.web.common/src/org/jetbrains/kotlin/fir/analysis/web/common/checkers/declaration/FirWebCommonExternalPropertyAccessorChecker.kt b/compiler/fir/checkers/checkers.web.common/src/org/jetbrains/kotlin/fir/analysis/web/common/checkers/declaration/FirWebCommonExternalPropertyAccessorChecker.kt index ea068ea..7a2802e 100644 --- a/compiler/fir/checkers/checkers.web.common/src/org/jetbrains/kotlin/fir/analysis/web/common/checkers/declaration/FirWebCommonExternalPropertyAccessorChecker.kt +++ b/compiler/fir/checkers/checkers.web.common/src/org/jetbrains/kotlin/fir/analysis/web/common/checkers/declaration/FirWebCommonExternalPropertyAccessorChecker.kt
@@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.web.common.checkers.declaration +import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind @@ -18,7 +19,11 @@ object FirWebCommonExternalPropertyAccessorChecker : FirPropertyAccessorChecker(MppCheckerKind.Common) { override fun check(declaration: FirPropertyAccessor, context: CheckerContext, reporter: DiagnosticReporter) { - if (declaration !is FirDefaultPropertyAccessor && declaration.isDirectlyExternal()) { + if ( + declaration !is FirDefaultPropertyAccessor && + declaration.isDirectlyExternal() && + declaration.source?.elementType == KtNodeTypes.PROPERTY_ACCESSOR + ) { reporter.reportOn(declaration.source, FirWebCommonErrors.WRONG_EXTERNAL_DECLARATION, "property accessor", context) } }
diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirKeywordUtils.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirKeywordUtils.kt index e408b4f..cc72483 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirKeywordUtils.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirKeywordUtils.kt
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtValVarKeywordOwner import org.jetbrains.kotlin.util.getChildren +import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment +import org.jetbrains.kotlin.utils.exceptions.withPsiEntry // DO // - use this to retrieve modifiers on the source and confirm a certain modifier indeed appears @@ -93,11 +95,12 @@ is KtPsiSourceElement -> { val modifierListOwner = psi as? KtModifierListOwner - // TODO: drop in the context of KT-72295 // The check is required in the Analysis API mode as in this case property accessor // has the containing property as a source if (kind == KtFakeSourceElementKind.DelegatedPropertyAccessor && modifierListOwner is KtProperty) { - return null + errorWithAttachment("Don't request modifiers on fake PSI of delegated property accessors, it's not the right PSI") { + withPsiEntry("property", modifierListOwner) + } } modifierListOwner?.modifierList?.let { FirModifierList.FirPsiModifierList(it) } @@ -113,9 +116,14 @@ operator fun FirModifierList?.contains(token: KtModifierKeywordToken): Boolean = this?.contains(token) == true -fun FirElement.getModifier(token: KtModifierKeywordToken): FirModifier<*>? = source.getModifierList()?.get(token) +fun FirElement.getModifierList(): FirModifierList? = when { + source?.kind == KtFakeSourceElementKind.DelegatedPropertyAccessor && source?.elementType != KtNodeTypes.PROPERTY_ACCESSOR -> null + else -> source.getModifierList() +} -fun FirElement.hasModifier(token: KtModifierKeywordToken): Boolean = token in source.getModifierList() +fun FirElement.getModifier(token: KtModifierKeywordToken): FirModifier<*>? = getModifierList()?.get(token) + +fun FirElement.hasModifier(token: KtModifierKeywordToken): Boolean = token in getModifierList() @OptIn(SymbolInternals::class) fun FirBasedSymbol<*>.hasModifier(token: KtModifierKeywordToken): Boolean = fir.hasModifier(token)
diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt index e3d8eac..0ad2f87 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt
@@ -1427,7 +1427,8 @@ baseModuleData, classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol, context = context, - isExtension = false + isExtension = false, + explicitDeclarationSource = propertySource, ) } else { this.isLocal = false @@ -1503,6 +1504,7 @@ classWrapper?.classBuilder?.ownerRegularOrAnonymousObjectSymbol, context, isExtension = receiverTypeNode != null, + explicitDeclarationSource = propertySource, ) } }
diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt index b66aa50..12d1893 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt
@@ -58,11 +58,6 @@ val baseScopeProvider: FirScopeProvider, bodyBuildingMode: BodyBuildingMode = BodyBuildingMode.NORMAL, ) : AbstractRawFirBuilder<PsiElement>(session) { - /** - * @see generateAccessorsByDelegate - */ - protected open val KtProperty.sourceForDelegatedPropertyAccessors: KtSourceElement? get() = null - protected open fun bindFunctionTarget(target: FirFunctionTarget, function: FirFunction) { target.bind(function) } @@ -2332,6 +2327,7 @@ ownerRegularOrAnonymousObjectSymbol = null, context = context, isExtension = false, + explicitDeclarationSource = propertySource, ) } } else { @@ -2413,7 +2409,7 @@ lazyDelegateExpression = lazyDelegateExpression, lazyBodyForGeneratedAccessors = lazyBody, bindFunction = ::bindFunctionTarget, - explicitDeclarationSource = sourceForDelegatedPropertyAccessors, + explicitDeclarationSource = propertySource, ) } }
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 4ac78a6..cdc3f94 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
@@ -310,14 +310,6 @@ is FirRegularClassBuilder -> symbol } -/** - * TODO: KT-72295 – the compiler should provide [explicitDeclarationSource] as well. - * - * @param explicitDeclarationSource In the Analysis API mode, this function is called at least twice – during [FirResolvePhase.RAW_FIR] in lazy mode, - * and the next time to calculate lazy body. - * This means that `fakeSource` will be different in these two situations after KT-64898. - * As declarations (such as property accessors and the setter parameter) cannot be changed after creation, so it has to be stable. - */ fun <T> FirPropertyBuilder.generateAccessorsByDelegate( delegateBuilder: FirWrappedDelegateExpressionBuilder?, moduleData: FirModuleData,
diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.diag.txt b/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.diag.txt index 0aeccaa..8265800 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.diag.txt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.diag.txt
@@ -10,10 +10,6 @@ val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics -/foo.kt:20:53: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.<get-myDelegated>|<get-myDelegated>(){}[0]): - fun `<get-myDelegated>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics - fun `<get-myDelegated>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics - /foo.kt:22:1: error: Platform declaration clash: The following properties have the same IR signature (com.example.klib.serialization.diagnostics/extensionValue|@kotlin.Int{}extensionValue[0]): val kotlin.Int.extensionValue: kotlin.Int defined in com.example.klib.serialization.diagnostics var kotlin.Int.extensionValue: kotlin.Int defined in com.example.klib.serialization.diagnostics @@ -50,10 +46,6 @@ val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics -/main.kt:37:52: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.<get-myDelegated>|<get-myDelegated>(){}[0]): - fun `<get-myDelegated>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics - fun `<get-myDelegated>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics - /main.kt:39:1: error: Platform declaration clash: The following properties have the same IR signature (com.example.klib.serialization.diagnostics/extensionValue|@kotlin.Int{}extensionValue[0]): val kotlin.Int.extensionValue: kotlin.Int defined in com.example.klib.serialization.diagnostics var kotlin.Int.extensionValue: kotlin.Int defined in com.example.klib.serialization.diagnostics
diff --git a/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.kt b/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.kt index da4f4d6..ae16c5a 100644 --- a/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.kt +++ b/compiler/testData/diagnostics/klibSerializationTests/signatureClashVariables.kt
@@ -17,7 +17,7 @@ <!CONFLICTING_KLIB_SIGNATURES_ERROR!><!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val valueSeparateFiles<!> = 0<!> -<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val myDelegated: Long by <!CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 0L }<!><!> +<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val myDelegated: Long by lazy { 0L }<!> <!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") var Int.extensionValue: Int @@ -34,7 +34,7 @@ <!CONFLICTING_KLIB_SIGNATURES_ERROR!><!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val valueSingleFile: Int<!> = 0<!> <!CONFLICTING_KLIB_SIGNATURES_ERROR!><!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val valueSingleFile: String<!> = ""<!> -<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val myDelegated: Int by <!CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 1 }<!><!> +<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val myDelegated: Int by lazy { 1 }<!> <!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION") val Int.extensionValue: Int
diff --git a/compiler/testData/ir/sourceRanges/declarations/delegatedProperties.fir.txt b/compiler/testData/ir/sourceRanges/declarations/delegatedProperties.fir.txt index b54990a..de46623 100644 --- a/compiler/testData/ir/sourceRanges/declarations/delegatedProperties.fir.txt +++ b/compiler/testData/ir/sourceRanges/declarations/delegatedProperties.fir.txt
@@ -13,8 +13,8 @@ @7:8..9 BLOCK_BODY @7:9..9 RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Int declared in <root>.MyClass.lazyProp$delegate' @7:8..9 CONST Int type=kotlin.Int value=5 - @6:20..8:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.Int - @6:20..8:5 VALUE_PARAMETER name:<this> type:<root>.MyClass + @6:4..8:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.Int + @6:4..8:5 VALUE_PARAMETER name:<this> type:<root>.MyClass @6:20..8:5 BLOCK_BODY @6:20..8:5 RETURN type=kotlin.Nothing from='public final fun <get-lazyProp> (): kotlin.Int declared in <root>.MyClass' @6:20..8:5 CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.getValue [inline,operator] declared in kotlin' type=kotlin.Int origin=null @@ -40,8 +40,8 @@ @11:22..25 GET_VAR 'old: kotlin.String declared in <root>.MyClass.observableProp$delegate.<anonymous>' type=kotlin.String origin=null @11:25..31 CONST String type=kotlin.String value=", now " @11:32..35 GET_VAR 'new: kotlin.String declared in <root>.MyClass.observableProp$delegate.<anonymous>' type=kotlin.String origin=null - @10:34..12:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-observableProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.String - @10:34..12:5 VALUE_PARAMETER name:<this> type:<root>.MyClass + @10:4..12:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-observableProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.String + @10:4..12:5 VALUE_PARAMETER name:<this> type:<root>.MyClass @10:34..12:5 BLOCK_BODY @10:34..12:5 RETURN type=kotlin.Nothing from='public final fun <get-observableProp> (): kotlin.String declared in <root>.MyClass' @10:34..12:5 CALL 'public abstract fun getValue (thisRef: T of kotlin.properties.ReadWriteProperty, property: kotlin.reflect.KProperty<*>): V of kotlin.properties.ReadWriteProperty [operator] declared in kotlin.properties.ReadWriteProperty' type=kotlin.String origin=null @@ -51,7 +51,7 @@ @10:34..12:5 PROPERTY_REFERENCE 'public final observableProp: kotlin.String [delegated,var] declared in <root>.MyClass' field=null getter='public final fun <get-observableProp> (): kotlin.String declared in <root>.MyClass' setter='public final fun <set-observableProp> (<set-?>: kotlin.String): kotlin.Unit declared in <root>.MyClass' type=kotlin.reflect.KMutableProperty1<<root>.MyClass, kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE @10:4..12:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<set-observableProp> visibility:public modality:FINAL <> ($this:<root>.MyClass, <set-?>:kotlin.String) returnType:kotlin.Unit @10:4..12:5 VALUE_PARAMETER name:<this> type:<root>.MyClass - @10:34..12:5 VALUE_PARAMETER name:<set-?> index:0 type:kotlin.String + @10:4..12:5 VALUE_PARAMETER name:<set-?> index:0 type:kotlin.String @10:34..12:5 BLOCK_BODY @10:34..12:5 RETURN type=kotlin.Nothing from='public final fun <set-observableProp> (<set-?>: kotlin.String): kotlin.Unit declared in <root>.MyClass' @10:34..12:5 CALL 'public abstract fun setValue (thisRef: T of kotlin.properties.ReadWriteProperty, property: kotlin.reflect.KProperty<*>, value: V of kotlin.properties.ReadWriteProperty): kotlin.Unit [operator] declared in kotlin.properties.ReadWriteProperty' type=kotlin.Unit origin=null
diff --git a/compiler/testData/ir/sourceRanges/kt24258.fir.txt b/compiler/testData/ir/sourceRanges/kt24258.fir.txt index 8d3e52e..c8d7ed4 100644 --- a/compiler/testData/ir/sourceRanges/kt24258.fir.txt +++ b/compiler/testData/ir/sourceRanges/kt24258.fir.txt
@@ -8,7 +8,7 @@ @3:37..51 BLOCK_BODY @3:51..51 RETURN type=kotlin.Nothing from='local final fun <anonymous> (): @[FlexibleNullability] kotlin.String? declared in <root>.lazyNullString$delegate' @3:39..51 CALL 'public open fun nullString (): @[FlexibleNullability] kotlin.String? declared in <root>.J' type=@[FlexibleNullability] kotlin.String? origin=null - @3:30..53 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyNullString> visibility:public modality:FINAL <> () returnType:kotlin.String + @3:0..53 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyNullString> visibility:public modality:FINAL <> () returnType:kotlin.String @3:30..53 BLOCK_BODY @3:30..53 RETURN type=kotlin.Nothing from='public final fun <get-lazyNullString> (): kotlin.String declared in <root>' @3:30..53 TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
diff --git a/js/js.translator/testData/lineNumbers/delegateMemberVal.kt b/js/js.translator/testData/lineNumbers/delegateMemberVal.kt index e4ebda6..e2a78de 100644 --- a/js/js.translator/testData/lineNumbers/delegateMemberVal.kt +++ b/js/js.translator/testData/lineNumbers/delegateMemberVal.kt
@@ -13,5 +13,5 @@ } } -// LINES(FIR JS_IR): 3 3 3 3 1 1 3 3 3 3 3 3 6 6 7 7 10 10 10 10 10 10 10 11 12 12 3 3 18 * 3 +// LINES(FIR JS_IR): 3 3 3 3 1 1 3 3 3 2 3 3 3 6 6 7 7 10 10 10 10 10 10 10 11 12 12 3 3 18 * 3 // LINES(ClassicFrontend JS_IR): 3 3 3 3 1 1 3 3 3 2 3 3 3 2 1 2 6 6 7 7 10 10 10 10 10 10 10 11 12 12 2 2 18 * 2
diff --git a/js/js.translator/testData/lineNumbers/delegatedProperty.kt b/js/js.translator/testData/lineNumbers/delegatedProperty.kt index 5aa9ea8..f928d43 100644 --- a/js/js.translator/testData/lineNumbers/delegatedProperty.kt +++ b/js/js.translator/testData/lineNumbers/delegatedProperty.kt
@@ -16,4 +16,4 @@ } // LINES(ClassicFrontend JS_IR): 3 3 5 5 4 5 5 5 4 1 4 5 4 5 5 5 4 1 4 8 8 9 10 10 13 14 14 4 4 20 * 4 20 * 4 4 20 * 4 20 -// LINES(FIR JS_IR): 3 3 5 5 4 5 5 5 5 5 5 8 8 9 10 10 13 14 14 5 5 20 * 5 20 * 5 5 20 * 5 20 +// LINES(FIR JS_IR): 3 3 5 5 4 5 5 5 4 5 5 5 8 8 9 10 10 13 14 14 5 5 20 * 5 20 * 5 5 20 * 5 20
diff --git a/native/native.tests/testData/klib/cross-compilation/identity/multiModuleSmoke.ir.md5.txt b/native/native.tests/testData/klib/cross-compilation/identity/multiModuleSmoke.ir.md5.txt index 9daae22..d0ef771 100644 --- a/native/native.tests/testData/klib/cross-compilation/identity/multiModuleSmoke.ir.md5.txt +++ b/native/native.tests/testData/klib/cross-compilation/identity/multiModuleSmoke.ir.md5.txt
@@ -1,7 +1,7 @@ // MODULE: lib1 458e9c7fbfa8d6be07012ceae7966000 // MODULE: lib2 -271c036445988984cc12d0ec5ff65834 +67b9138ecb341c17c955d4545ee4b941 // MODULE: lib3 6e66eb4ff348419f4834cec413ea44bf // MODULE: app
diff --git a/plugins/compose/compiler-hosted/integration-tests/src/jvmTest/kotlin/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt b/plugins/compose/compiler-hosted/integration-tests/src/jvmTest/kotlin/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt index 966b445..9f1afe4 100644 --- a/plugins/compose/compiler-hosted/integration-tests/src/jvmTest/kotlin/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt +++ b/plugins/compose/compiler-hosted/integration-tests/src/jvmTest/kotlin/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt
@@ -1443,6 +1443,7 @@ @Test fun testComposableValueOperator() { + assumeTrue(!useFir) check( """ import androidx.compose.runtime.Composable @@ -1495,6 +1496,61 @@ } @Test + fun testComposableValueOperatorK2() { + // The output is mostly the same except for one diagnostic placement. + assumeTrue(useFir) + check( + """ + import androidx.compose.runtime.Composable + import kotlin.reflect.KProperty + + class Foo + class FooDelegate { + @Composable + operator fun getValue(thisObj: Any?, property: KProperty<*>) {} + @Composable + operator fun <!COMPOSE_INVALID_DELEGATE!>setValue<!>(thisObj: Any?, property: KProperty<*>, value: Any) {} + } + @Composable operator fun Foo.getValue(thisObj: Any?, property: KProperty<*>) {} + @Composable operator fun Foo.<!COMPOSE_INVALID_DELEGATE!>setValue<!>(thisObj: Any?, property: KProperty<*>, value: Any) {} + + fun <!COMPOSABLE_EXPECTED!>nonComposable<!>() { + val fooValue = Foo() + val foo by fooValue + val fooDelegate by FooDelegate() + var <!COMPOSE_INVALID_DELEGATE!>mutableFoo<!> by fooValue + val bar = Bar() + + println(<!COMPOSABLE_INVOCATION!>foo<!>) + println(<!COMPOSABLE_INVOCATION!>fooDelegate<!>) + println(bar.<!COMPOSABLE_INVOCATION!>foo<!>) + + <!COMPOSABLE_INVOCATION!>mutableFoo<!> = Unit + } + + @Composable + fun TestComposable() { + val fooValue = Foo() + val foo by fooValue + val fooDelegate by FooDelegate() + val bar = Bar() + + println(foo) + println(fooDelegate) + println(bar.foo) + } + + class Bar { + val <!COMPOSABLE_EXPECTED!>foo<!> by Foo() + + @get:Composable + val foo2 by Foo() + } + """ + ) + } + + @Test fun testComposableFunInterfaceInNonComposableFunction() { check( """
diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/anonymousDelegate.fir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/anonymousDelegate.fir.txt deleted file mode 100644 index 72d1b2e..0000000 --- a/plugins/kapt3/kapt3-compiler/testData/converter/anonymousDelegate.fir.txt +++ /dev/null
@@ -1,140 +0,0 @@ -import kotlin.reflect.KProperty; - -/** - * package { - * - * // field: delegate$delegate:Ljava/lang/Object; - * // getter: getDelegate()Ljava/lang/Object; - * // setter: setDelegate(Ljava/lang/Object;)V - * public final (* delegated *) var delegate: kotlin/Any - * public final (* non-default *) get - * public final (* non-default *) set(<set-?>: kotlin/Any) - * - * // module name: main - * } - */ -@kotlin.Metadata() -public final class AnonymousDelegateKt { - @org.jetbrains.annotations.NotNull() - private static final java.lang.Object delegate$delegate = null; - - public static final void setDelegate(@org.jetbrains.annotations.NotNull() - java.lang.Object p0) { - } - - @org.jetbrains.annotations.NotNull() - public static final java.lang.Object getDelegate() { - return null; - } -} - -//////////////////// - - -import kotlin.reflect.KProperty; - -/** - * public final class ConcreteDelegate : kotlin/Any { - * - * // signature: <init>()V - * public constructor() - * - * // signature: getValue(Ljava/lang/Object;Lkotlin/reflect/KProperty;)I - * public final operator fun getValue(t: kotlin/Any?, p: kotlin/reflect/KProperty<*>): kotlin/Int - * - * // module name: main - * } - */ -@kotlin.Metadata() -public final class ConcreteDelegate { - - public ConcreteDelegate() { - super(); - } - - public final int getValue(@org.jetbrains.annotations.Nullable() - java.lang.Object t, @org.jetbrains.annotations.NotNull() - kotlin.reflect.KProperty<?> p) { - return 0; - } -} - -//////////////////// - - -import kotlin.reflect.KProperty; - -/** - * public final class Test : kotlin/Any { - * - * // signature: <init>()V - * public constructor() - * - * // field: broken$delegate:Ljava/lang/Object; - * // getter: getBroken()Ljava/lang/Object; - * // setter: setBroken(Ljava/lang/Object;)V - * public final (* delegated *) var broken: kotlin/Any - * public final (* non-default *) get - * public final (* non-default *) set(<set-?>: kotlin/Any) - * - * // field: concreteDelegate$delegate:LConcreteDelegate; - * // getter: getConcreteDelegate()I - * public final (* delegated *) val concreteDelegate: kotlin/Int - * public final (* non-default *) get - * - * // field: lazyProp$delegate:Lkotlin/Lazy; - * // getter: getLazyProp()Ljava/lang/Runnable; - * private final (* delegated *) val lazyProp: java/lang/Runnable - * private final (* non-default *) get - * - * // field: overridden$delegate:Ljava/io/Serializable; - * // getter: getOverridden()Ljava/lang/Object; - * // setter: setOverridden(Ljava/lang/Object;)V - * public final (* delegated *) var overridden: kotlin/Any - * public final (* non-default *) get - * public final (* non-default *) set(<set-?>: kotlin/Any) - * - * // module name: main - * } - */ -@kotlin.Metadata() -public final class Test { - @org.jetbrains.annotations.NotNull() - private final java.lang.Object broken$delegate = null; - @org.jetbrains.annotations.NotNull() - private final java.io.Serializable overridden$delegate = null; - @org.jetbrains.annotations.NotNull() - private final kotlin.Lazy lazyProp$delegate = null; - @org.jetbrains.annotations.NotNull() - private final ConcreteDelegate concreteDelegate$delegate = null; - - public Test() { - super(); - } - - public final void setBroken(@org.jetbrains.annotations.NotNull() - java.lang.Object p0) { - } - - @org.jetbrains.annotations.NotNull() - public final java.lang.Object getBroken() { - return null; - } - - public final void setOverridden(@org.jetbrains.annotations.NotNull() - java.lang.Object p0) { - } - - @org.jetbrains.annotations.NotNull() - public final java.lang.Object getOverridden() { - return null; - } - - private final java.lang.Runnable getLazyProp() { - return null; - } - - public final int getConcreteDelegate() { - return 0; - } -}