diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.fir.txt new file mode 100644 index 00000000000..c625b85a47e --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.fir.txt @@ -0,0 +1,28 @@ +FILE: backingFieldModifiers.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val a: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val b: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val c: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val d: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val e: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val f: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val g: R|kotlin/Number| + public get(): R|kotlin/Number| + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt new file mode 100644 index 00000000000..b5884f32db1 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt @@ -0,0 +1,22 @@ +class A { + val a: Number + abstract field = 1 + + val b: Number + open field = 1 + + val c: Number + final field = 1 + + val d: Number + inline field = 1 + + val e: Number + noinline field = 1 + + val f: Number + crossinline field = 1 + + val g: Number + tailrec field = 1 +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.fir.txt new file mode 100644 index 00000000000..be2d478e6d5 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.fir.txt @@ -0,0 +1,41 @@ +Module: lib +FILE: A.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val a: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val b: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val c: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val d: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final fun rest(): R|kotlin/Unit| { + lval aI: R|kotlin/Int| = R|/A.A|().R|/A.a|.R|kotlin/Int.plus|(Int(10)) + lval bI: R|kotlin/Int| = R|/A.A|().R|/A.b|.R|kotlin/Int.plus|(Int(20)) + lval cI: = R|/A.A|().R|/A.c|.#(Int(30)) + lval dI: = R|/A.A|().R|/A.d|.#(Int(40)) + } + + } + public final fun test(): R|kotlin/Unit| { + lval aA: = R|/A.A|().R|/A.a|.#(Int(10)) + lval bA: R|kotlin/Int| = R|/A.A|().R|/A.b|.R|kotlin/Int.plus|(Int(20)) + lval cA: = R|/A.A|().R|/A.c|.#(Int(30)) + lval dA: = R|/A.A|().R|/A.d|.#(Int(40)) + } +Module: main +FILE: B.kt + public final fun main(): R|kotlin/Unit| { + lval aB: = R|/A.A|().R|/A.a|.#(Int(10)) + lval bB: = R|/A.A|().R|/A.b|.#(Int(20)) + lval cB: = R|/A.A|().R|/A.c|.#(Int(30)) + lval dB: = R|/A.A|().R|/A.d|.#(Int(40)) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt new file mode 100644 index 00000000000..963c85ae7c9 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt @@ -0,0 +1,40 @@ +// MODULE: lib +// FILE: A.kt + +class A { + val a: Number + private field = 1 + + val b: Number + internal field = 2 + + val c: Number + protected field = 3 + + val d: Number + public field = 5 + + fun rest() { + val aI = A().a + 10 + val bI = A().b + 20 + val cI = A().c + 30 + val dI = A().d + 40 + } +} + +fun test() { + val aA = A().a + 10 + val bA = A().b + 20 + val cA = A().c + 30 + val dA = A().d + 40 +} + +// MODULE: main(lib) +// FILE: B.kt + +fun main() { + val aB = A().a + 10 + val bB = A().b + 20 + val cB = A().c + 30 + val dB = A().d + 40 +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.fir.txt new file mode 100644 index 00000000000..698030afacf --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.fir.txt @@ -0,0 +1,6 @@ +FILE: backingFieldWithSmartTypeParameters.kt + public final val items: R|kotlin/collections/List| + public get(): R|kotlin/collections/List| + public final fun test(): R|kotlin/Unit| { + R|/items|.R|SubstitutionOverride|(String(one more item)) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt new file mode 100644 index 00000000000..7fe46de630b --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt @@ -0,0 +1,6 @@ +val items: List + field = mutableListOf() + +fun test() { + items.add("one more item") +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.fir.txt new file mode 100644 index 00000000000..4b958d93460 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.fir.txt @@ -0,0 +1,6 @@ +FILE: explicitBackingFieldInInterface.kt + public abstract interface I : R|kotlin/Any| { + public abstract val it: R|kotlin/Number| + public get(): R|kotlin/Number| + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt new file mode 100644 index 00000000000..abbf7ae2e90 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt @@ -0,0 +1,4 @@ +interface I { + val it: Number + field = 10 +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.fir.txt new file mode 100644 index 00000000000..d31823ad2f8 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.fir.txt @@ -0,0 +1,49 @@ +FILE: explicitBackingFieldType.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val a: R|kotlin/Int| = Int(20) + public get(): R|kotlin/Int| + + public final val it: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val joke: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val incompatible: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val customGetterNeeded: R|kotlin/Int| + public get(): R|kotlin/Int| + + public final val invertedTypes: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(30) + } + + public final val uninitialized: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final val uninitializedWithGetter: R|kotlin/Number| + public get(): R|kotlin/Number| { + ^ Int(2) + } + + public final val initiaizedWithExplicitBackingField: R|kotlin/collections/List| = R|kotlin/collections/listOf|(vararg(Int(1), Int(2))) + public get(): R|kotlin/collections/List| + + public final val p: R|kotlin/Int| = Int(5) + public get(): R|kotlin/Int| { + ^ this@R|/A|.F|/A.p| + } + + public final var setterNeeded: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ this@R|/A|.F|/A.setterNeeded|.R|kotlin/String.length| + } + public set(value: R|kotlin/Int|): R|kotlin/Unit| + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt new file mode 100644 index 00000000000..308981291a5 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt @@ -0,0 +1,36 @@ +class A { + val a = 20 + + val it: Number + field = 4 + + val joke: Number + field = "Haha" + + val incompatible: Number + field: Any? = 42 + + val customGetterNeeded: Int + field: Number = 42 + + val invertedTypes: Int + field: Number = 42 + get() = 30 + + val uninitialized: Number + field: Int + + val uninitializedWithGetter: Number + field: Int + get() = 2 + + val initiaizedWithExplicitBackingField = listOf(1, 2) + field: MutableList + + val p = 5 + get() = field + + var setterNeeded: Int + field = "test" + get() = field.length +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.fir.txt new file mode 100644 index 00000000000..d81a414de45 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.fir.txt @@ -0,0 +1,8 @@ +FILE: explicitBackingFieldsWithDelegates.kt + public final val thingWithDelefate: R|kotlin/Number|by R|kotlin/lazy|( = lazy@fun (): R|kotlin/Number| { + ^ (Int(2) as R|kotlin/Number|) + } + ) + public get(): R|kotlin/Number| { + ^ D|/thingWithDelefate|.R|kotlin/getValue|(Null(null), ::R|/thingWithDelefate|) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt new file mode 100644 index 00000000000..32977f0faea --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt @@ -0,0 +1,2 @@ +val thingWithDelefate by lazy { 2 as Number } + field = 10 diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.fir.txt new file mode 100644 index 00000000000..49a2c8c6146 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.fir.txt @@ -0,0 +1,6 @@ +FILE: filePrivateBackingFieldAccess.kt + public final val list: R|kotlin/collections/List| + public get(): R|kotlin/collections/List| + public final fun add(s: R|kotlin/String|): R|kotlin/Unit| { + R|/list|.R|SubstitutionOverride|(R|/s|) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt new file mode 100644 index 00000000000..d71b5697aaa --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt @@ -0,0 +1,6 @@ +val list: List + field = mutableListOf() + +fun add(s: String) { + list.add(s) +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.fir.txt new file mode 100644 index 00000000000..dbb883cc3e8 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.fir.txt @@ -0,0 +1,31 @@ +FILE: lateinitBackingFields.kt + public final var that: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ F|/that|.R|kotlin/String.length| + } + public set(value: R|kotlin/Int|): R|kotlin/Unit| { + F|/that| = R|/value|.R|kotlin/Any.toString|() + } + public final fun test(): R|kotlin/Unit| { + R|/that| = Int(1) + R|kotlin/io/println|(R|/that|) + } + public final lateinit var number: R|kotlin/Number| + public get(): R|kotlin/Number| + public set(value: R|kotlin/Number|): R|kotlin/Unit| { + F|/number| = Int(10) + } + public final val something: R|kotlin/Number| + public get(): R|kotlin/Number| + public final lateinit var oneMore: R|kotlin/Number| + public get(): R|kotlin/Number| + public set(value: R|kotlin/Number|): R|kotlin/Unit| { + F|/oneMore| = Int(10) + } + public final var thingWithNullableField: R|kotlin/Number| + public get(): R|kotlin/Number| { + ^ Int(20) + } + public set(value: R|kotlin/Number|): R|kotlin/Unit| { + F|/thingWithNullableField| = R|/value|.R|kotlin/Any.toString|() + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt new file mode 100644 index 00000000000..972c7d39b50 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt @@ -0,0 +1,35 @@ +var that: Int + lateinit field: String + get() = field.length + set(value) { + field = value.toString() + } + +fun test() { + that = 1 + println(that) +} + +// Not allowed for properties with +// custom accessors +lateinit var number: Number + field = 4 + set(value) { + field = 10 + } + +val something: Number + lateinit field = 4 + +lateinit var oneMore: Number + lateinit field = 4 + set(value) { + field = 10 + } + +var thingWithNullableField: Number + lateinit field: String? + get() = 20 + set(value) { + field = value.toString() + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.fir.txt new file mode 100644 index 00000000000..a225361cd37 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.fir.txt @@ -0,0 +1,31 @@ +FILE: localVariablesWithBackingFields.kt + public final val that: R|kotlin/Number| + public get(): R|kotlin/Number| + public final fun test(): R|kotlin/Unit| { + lval a: R|kotlin/Number| + # = Int(1) + lval b: R|kotlin/Number|by R|kotlin/lazy|( = lazy@fun (): R|kotlin/Int| { + ^ Int(2) + } + ) + # = Int(10) + } + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val c: R|kotlin/Number|by R|kotlin/lazy|( = lazy@fun (): R|kotlin/Int| { + ^ Int(2) + } + ) + public get(): R|kotlin/Number| { + ^ this@R|/A|.D|/A.c|.R|kotlin/getValue|(this@R|/A|, ::R|/A.c|) + } + + } + public final val R|A|.cc: R|kotlin/Number| + public get(): R|kotlin/Number| + public final fun R|A|.cc(): R|kotlin/Unit| { + lval it: = #.#(Int(2)) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt new file mode 100644 index 00000000000..e2ef070b194 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt @@ -0,0 +1,22 @@ +val that: Number + field = 239 + +fun test() { + val a: Number + field = 1 + + val b: Number by lazy { 2 } + field = 10 +} + +class A { + val c: Number by lazy { 2 } + field = 10 +} + +val A.cc: Number + field = 10 + +fun A.cc() { + val it = a + 2 +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.fir.txt new file mode 100644 index 00000000000..81fadcabbbf --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.fir.txt @@ -0,0 +1,30 @@ +FILE: overriddenPropertiesWithExplicitBackingFields.kt + public open class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public open var it: R|kotlin/Number| + public get(): R|kotlin/Number| + public set(value: R|kotlin/Number|): R|kotlin/Unit| { + this@R|/A|.F|/A.it| = R|/value|.R|kotlin/Number.toInt|() + } + + public final fun test(): R|kotlin/Unit| { + #(this@R|/A|.R|/A.it|.#(Int(1))) + } + + } + public open class B : R|A| { + public constructor(): R|B| { + super() + } + + public open override var it: R|kotlin/Number| + public get(): R|kotlin/Number| { + ^ Double(3.14) + } + public set(value: R|kotlin/Number|): R|kotlin/Unit| { + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt new file mode 100644 index 00000000000..d018472721b --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt @@ -0,0 +1,20 @@ +open class A { + open var it: Number + private field = 3 + set(value) { + field = value.toInt() + } + + fun test() { + // error, because `it` is not + // final, so no smart type narrowing + // is provided + println(it + 1) + } +} + +open class B : A() { + override var it: Number + get() = 3.14 + set(value) {} +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.fir.txt new file mode 100644 index 00000000000..f1f6c6808a8 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.fir.txt @@ -0,0 +1,24 @@ +FILE: propertyTypeNarrowing.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val it: R|kotlin/Number| + public get(): R|kotlin/Number| + + public final fun test(): R|kotlin/Int| { + ^test this@R|/A|.R|/A.it|.R|kotlin/Int.plus|(Int(3)) + } + + public final val p: R|kotlin/Int| = Int(5) + public get(): R|kotlin/Int| { + ^ this@R|/A|.F|/A.p| + } + + } + public final fun test(): R|kotlin/Unit| { + lval c: = R|/A.A|().R|/A.it|.#(Int(1)) + lval d: R|kotlin/Unit| = R|/test|() + lval b: R|kotlin/Int| = R|/A.A|().R|/A.p|.R|kotlin/Int.plus|(Int(2)) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt new file mode 100644 index 00000000000..ebd1d9e3ca0 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt @@ -0,0 +1,15 @@ +class A { + val it: Number + field = 4 + + fun test() = it + 3 + + val p = 5 + get() = field +} + +fun test() { + val c = A().it + 1 + val d = test() + val b = A().p + 2 +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.fir.txt new file mode 100644 index 00000000000..beaec6f87c5 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.fir.txt @@ -0,0 +1,10 @@ +FILE: randomWeirdBackingFields.kt + public abstract class Some1 : R|kotlin/Any| { + public constructor(): R|Some1| { + super() + } + + public abstract val foo: R|kotlin/collections/List| + public get(): R|kotlin/collections/List| + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt new file mode 100644 index 00000000000..39845ee2831 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt @@ -0,0 +1,4 @@ +abstract class Some1 { + abstract val foo: List + internal field = mutableListOf() +} diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.fir.txt new file mode 100644 index 00000000000..88536b92d68 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.fir.txt @@ -0,0 +1,3 @@ +FILE: redundantExplicitBackingField.kt + public final val it: R|kotlin/Int| + public get(): R|kotlin/Int| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt new file mode 100644 index 00000000000..351a70c9592 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt @@ -0,0 +1,2 @@ +val it: Int + field = 42 diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index c1cb76520ee..d585f74f667 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -5532,6 +5532,104 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { } } + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("backingFieldModifiers.kt") + public void testBackingFieldModifiers() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt"); + } + + @Test + @TestMetadata("backingFieldVisibility.kt") + public void testBackingFieldVisibility() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt"); + } + + @Test + @TestMetadata("backingFieldWithSmartTypeParameters.kt") + public void testBackingFieldWithSmartTypeParameters() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldInInterface.kt") + public void testExplicitBackingFieldInInterface() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldType.kt") + public void testExplicitBackingFieldType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldsWithDelegates.kt") + public void testExplicitBackingFieldsWithDelegates() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt"); + } + + @Test + @TestMetadata("filePrivateBackingFieldAccess.kt") + public void testFilePrivateBackingFieldAccess() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt"); + } + + @Test + @TestMetadata("lateinitBackingFields.kt") + public void testLateinitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt"); + } + + @Test + @TestMetadata("localVariablesWithBackingFields.kt") + public void testLocalVariablesWithBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt"); + } + + @Test + @TestMetadata("overriddenPropertiesWithExplicitBackingFields.kt") + public void testOverriddenPropertiesWithExplicitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt"); + } + + @Test + @TestMetadata("propertyTypeNarrowing.kt") + public void testPropertyTypeNarrowing() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt"); + } + + @Test + @TestMetadata("randomWeirdBackingFields.kt") + public void testRandomWeirdBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt"); + } + + @Test + @TestMetadata("redundantExplicitBackingField.kt") + public void testRedundantExplicitBackingField() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); + } + } + } + @Nested @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 01919c947e9..52fbd46eba9 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -5532,6 +5532,104 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos } } + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("backingFieldModifiers.kt") + public void testBackingFieldModifiers() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt"); + } + + @Test + @TestMetadata("backingFieldVisibility.kt") + public void testBackingFieldVisibility() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt"); + } + + @Test + @TestMetadata("backingFieldWithSmartTypeParameters.kt") + public void testBackingFieldWithSmartTypeParameters() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldInInterface.kt") + public void testExplicitBackingFieldInInterface() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldType.kt") + public void testExplicitBackingFieldType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldsWithDelegates.kt") + public void testExplicitBackingFieldsWithDelegates() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt"); + } + + @Test + @TestMetadata("filePrivateBackingFieldAccess.kt") + public void testFilePrivateBackingFieldAccess() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt"); + } + + @Test + @TestMetadata("lateinitBackingFields.kt") + public void testLateinitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt"); + } + + @Test + @TestMetadata("localVariablesWithBackingFields.kt") + public void testLocalVariablesWithBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt"); + } + + @Test + @TestMetadata("overriddenPropertiesWithExplicitBackingFields.kt") + public void testOverriddenPropertiesWithExplicitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt"); + } + + @Test + @TestMetadata("propertyTypeNarrowing.kt") + public void testPropertyTypeNarrowing() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt"); + } + + @Test + @TestMetadata("randomWeirdBackingFields.kt") + public void testRandomWeirdBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt"); + } + + @Test + @TestMetadata("redundantExplicitBackingField.kt") + public void testRedundantExplicitBackingField() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); + } + } + } + @Nested @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 110be18c9b8..1649f24385e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -22485,6 +22485,22 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.kt"); } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("trivialExplicitBackingFIeld.kt") + public void testTrivialExplicitBackingFIeld() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 3784b1b3e6f..a8560113e41 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -22485,6 +22485,22 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.kt"); } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("trivialExplicitBackingFIeld.kt") + public void testTrivialExplicitBackingFIeld() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 75b6c93ef0a..9e5f05ae1ed 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -610,13 +610,7 @@ class Fir2IrDeclarationStorage( signature, containerSource ) { symbol -> - val accessorReturnType = if (isSetter) { - irBuiltIns.unitType - } else if (property.canNarrowDownGetterType) { - property.backingField?.returnTypeRef?.toIrType() ?: propertyType - } else { - propertyType - } + val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType val visibility = propertyAccessor?.visibility?.let { components.visibilityConverter.convertToDescriptorVisibility(it) } diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/backingFieldVisibility.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/backingFieldVisibility.kt new file mode 100644 index 00000000000..2e13bb9b7f9 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/backingFieldVisibility.kt @@ -0,0 +1,15 @@ +class A { + val a: Number + private field = 1 + + val b: Number + internal field = a + 3 +} + +fun box(): String { + return if (A().b + 20 == 24) { + "OK" + } else { + "fail: A().b = " + A().b.toString() + } +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField1.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField1.kt new file mode 100644 index 00000000000..10514c2e386 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField1.kt @@ -0,0 +1,8 @@ +class Base { + val x: CharSequence + internal field: String = "OK" +} + +fun box(): String { + return Base().x +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField2.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField2.kt new file mode 100644 index 00000000000..14af4cbb1bd --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField2.kt @@ -0,0 +1,10 @@ +class Base { + val x: CharSequence + internal field: String = "OK" + + val s: String get() = x +} + +fun box(): String { + return Base().s +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField3.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField3.kt new file mode 100644 index 00000000000..d4d37935f92 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField3.kt @@ -0,0 +1,9 @@ +class Base { + val x: CharSequence + internal field: String = "OK" + +} +val s: String get() = Base().x +fun box(): String { + return s +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField4.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField4.kt new file mode 100644 index 00000000000..58d133fd3df --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField4.kt @@ -0,0 +1,9 @@ +class Base { + val x: CharSequence + internal field: String = "OK" + +} +val s: String = Base().x +fun box(): String { + return s +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField5.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField5.kt new file mode 100644 index 00000000000..695a428310c --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField5.kt @@ -0,0 +1,13 @@ +open class Base { + open val x: CharSequence = "BASE" + // field = "BASE" +} + +class Ok : Base() { + override val x: CharSequence + internal field: String = "OK" +} + +fun box(): String { + return Ok().x +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/explicitBackingFieldInAnonymous.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/explicitBackingFieldInAnonymous.kt new file mode 100644 index 00000000000..20af546b765 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/explicitBackingFieldInAnonymous.kt @@ -0,0 +1,59 @@ +interface I { + val number: Number +} + +fun test1(): String? { + val it = object : I { + final override val number: Number + field = 10 + + val next get() = number + 1 + } + + return if (it.next != 11) { + "[1] ${it.number}, ${it.next}" + } else { + null + } +} + +fun test2(): String? { + class Local : I { + final override val number: Number + internal field = 42 + } + + return if (Local().number + 3 != 45) { + "[2] " + Local().number.toString() + } else { + null + } +} + +fun test3(): String? { + val it = object : I { + override val number: Number + field = "100" + get() { + return field.length + } + } + + return if (it.number != 3) { + "[3] " + it.number.toString() + } else { + null + } +} + +fun box(): String { + val problem = test1() + ?: test2() + ?: test3() + + return if (problem != null) { + "fail: " + problem + } else { + "OK" + } +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/getterReturnTypeWithBackingField.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/getterReturnTypeWithBackingField.kt new file mode 100644 index 00000000000..08605cead57 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/getterReturnTypeWithBackingField.kt @@ -0,0 +1,22 @@ +interface Storage { + val s: String +} + +class ImmutableStorage(override val s: String) : Storage +class MutableStorage(override var s: String) : Storage { + fun asImmutable() = ImmutableStorage(s) +} + +class My { + val storage: Storage + field = MutableStorage("OK") + get() = field.asImmutable() +} + +fun box(): String { + val my = My() + if (my.storage is MutableStorage) { + return "MUTABLE" + } + return my.storage.s +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/independentBackingFieldType.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/independentBackingFieldType.kt new file mode 100644 index 00000000000..857ad0b3166 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/independentBackingFieldType.kt @@ -0,0 +1,40 @@ +fun createString() = "AAA" + "BBB" + +class A { + var it: Int + field = 3.14 + get() = (field + 10).toInt() + set(value) { + field = (value - 10).toDouble() + + if (field < -3 || -1 < field) { + throw Exception("fail: value = $value, field = $field") + } + } + + var that: Int + field = createString() + "!" + get() = field.length + set(value) { + field = value.toString() + + if (field != "17") { + throw Exception("fail: value = $value, field = $field") + } + } +} + +fun box(): String { + try { + val a = A() + + val it: Int = A().it and 10 + a.it = it + + val that: Int = a.that + a.that = that + 10 + } catch (e: Exception) { + return e.message ?: "fail" + } + return "OK" +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/lateinitBackingFields.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/lateinitBackingFields.kt new file mode 100644 index 00000000000..63d7266338c --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/lateinitBackingFields.kt @@ -0,0 +1,16 @@ +var that: Int + lateinit field: String + get() = field.length + set(value) { + field = value.toString() + } + +fun box(): String { + that = 1 + + return if (that == 1) { + "OK" + } else { + "fail: $that" + } +} diff --git a/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt new file mode 100644 index 00000000000..469ecd54ec4 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/box/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt @@ -0,0 +1,30 @@ +open class A { + open var it: Number + private field = 3 + set(value) { + field = value.toInt() + } + + fun test(): String { + // Note that `it` is open, + // so no smart type narrowing + // is possible, and we expect + // here a call to the possibly + // overridden getter + return if (it.toInt() + 1 == 11) { + "OK" + } else { + "fail: $it" + } + } +} + +open class B : A() { + override var it: Number + get() = 10.12 + set(value) {} +} + +fun box(): String { + return B().test() +} diff --git a/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField/backingFieldWithSmartTypeParameters.kt b/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField/backingFieldWithSmartTypeParameters.kt new file mode 100644 index 00000000000..bd44af0b4f7 --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField/backingFieldWithSmartTypeParameters.kt @@ -0,0 +1,7 @@ +val items: List + field = mutableListOf() + +fun box(): String { + items.add("OK") + return items.last() +} diff --git a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.kt b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.kt new file mode 100644 index 00000000000..2accc0b333e --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.kt @@ -0,0 +1,13 @@ +// MODULE: ModuleA +// FILE: AI.kt + +public interface AI { + val number: Number +} + +// FILE: AC.kt + +public class AC : AI { + final override val number: Number + field = 4 +} diff --git a/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.txt b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.txt new file mode 100644 index 00000000000..e26c962c97d --- /dev/null +++ b/compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.txt @@ -0,0 +1,13 @@ +@kotlin.Metadata +public final class AC { + // source: 'AC.kt' + private final field number: int + public method (): void + public final @org.jetbrains.annotations.NotNull method getNumber(): java.lang.Number +} + +@kotlin.Metadata +public interface AI { + // source: 'AI.kt' + public abstract @org.jetbrains.annotations.NotNull method getNumber(): java.lang.Number +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt new file mode 100644 index 00000000000..73af05a7f69 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt @@ -0,0 +1,21 @@ +// FIR_IDENTICAL + +class A { + val a: Number + private field = 1 + + val b: Number + internal field = a + 2 + + val c = 1 + val d = c + 2 + + fun rest() { + val aI = A().a + 10 + val bI = A().b + 20 + } +} + +fun test() { + val bA = A().b + 20 +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt.txt new file mode 100644 index 00000000000..3e2db1dd04a --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt.txt @@ -0,0 +1,34 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: Int + field = 1 + get + + val b: Int + field = .().plus(other = 2) + get + + val c: Int + field = 1 + get + + val d: Int + field = .().plus(other = 2) + get + + fun rest() { + val aI: Int = A().().plus(other = 10) + val bI: Int = A().().plus(other = 20) + } + +} + +fun test() { + val bA: Int = A().().plus(other = 20) +} + diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.txt new file mode 100644 index 00000000000..774b86b87bc --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.txt @@ -0,0 +1,90 @@ +FILE fqName: fileName:/backingFieldVisibility.kt + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Number + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Number declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final]' type=kotlin.Number origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + PROPERTY name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.Int visibility:internal [final] + EXPRESSION_BODY + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Number declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .A declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=2 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Number + correspondingProperty: PROPERTY name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Number declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.Int visibility:internal [final]' type=kotlin.Number origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + PROPERTY name:c visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:c visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:c type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + PROPERTY name:d visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:d type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Int declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .A declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=2 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:d visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:d type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + FUN name:rest visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + VAR name:aI type:kotlin.Int [val] + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Number declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=10 + VAR name:bI type:kotlin.Int [val] + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Number declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=20 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:bA type:kotlin.Int [val] + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Number declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=20 diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt new file mode 100644 index 00000000000..a467840d7e4 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +class A { + val a = 20 + + val it: Number + field = 4 + + var invertedTypes: Int + field: Number = 42 + get() = if (field.toInt() > 10) field.toInt() else 10 + + val p = 5 + get() = field +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt.txt new file mode 100644 index 00000000000..db86318dc83 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt.txt @@ -0,0 +1,33 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: Int + field = 20 + get + + val it: Int + field = 4 + get + + var invertedTypes: Number + field = 42 + get(): Int { + return when { + greater(arg0 = .#invertedTypes.toInt(), arg1 = 10) -> .#invertedTypes.toInt() + else -> 10 + } + } + set + + val p: Int + field = 5 + get(): Int { + return .#p + } + +} + diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.txt new file mode 100644 index 00000000000..26124921fa9 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.txt @@ -0,0 +1,83 @@ +FILE fqName: fileName:/explicitBackingFieldType.kt + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=20 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + PROPERTY name:it visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=4 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Number + correspondingProperty: PROPERTY name:it visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Number declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Int visibility:private [final]' type=kotlin.Number origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + PROPERTY name:invertedTypes visibility:public modality:FINAL [var] + FIELD PROPERTY_BACKING_FIELD name:invertedTypes type:kotlin.Number visibility:private + EXPRESSION_BODY + CONST Int type=kotlin.Int value=42 + FUN name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:invertedTypes visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + WHEN type=kotlin.Int origin=IF + BRANCH + if: CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT + arg0: CALL 'public abstract fun toInt (): kotlin.Int declared in kotlin.Number' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:invertedTypes type:kotlin.Number visibility:private' type=kotlin.Number origin=GET_PROPERTY + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + arg1: CONST Int type=kotlin.Int value=10 + then: CALL 'public abstract fun toInt (): kotlin.Int declared in kotlin.Number' type=kotlin.Int origin=null + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:invertedTypes type:kotlin.Number visibility:private' type=kotlin.Number origin=GET_PROPERTY + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST Int type=kotlin.Int value=10 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A, :kotlin.Int) returnType:kotlin.Unit + correspondingProperty: PROPERTY name:invertedTypes visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name: index:0 type:kotlin.Int + BLOCK_BODY + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:invertedTypes type:kotlin.Number visibility:private' type=kotlin.Unit origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + value: GET_VAR ': kotlin.Int declared in .A.' type=kotlin.Int origin=null + PROPERTY name:p visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=5 + FUN name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:p visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=GET_PROPERTY + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt new file mode 100644 index 00000000000..22650f702c1 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class A { + var it: Int + field = 3.14 + get() = (field + 10).toInt() + set(value) { + field = (value - 10).toDouble() + } +} + +fun test() { + val a = A() + val it: Int = A().it and 10 + a.it = it +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt.txt new file mode 100644 index 00000000000..7182e37027b --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt.txt @@ -0,0 +1,23 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + var it: Double + field = 3.14 + get(): Int { + return .#it.plus(other = 10).toInt() + } + set(value: Int) { + .#it = value.minus(other = 10).toDouble() + } + +} + +fun test() { + val a: A = A() + val it: Int = A().().and(other = 10) + a.(value = it) +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.txt new file mode 100644 index 00000000000..5d9dc92ca62 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.txt @@ -0,0 +1,57 @@ +FILE fqName: fileName:/independentBackingFieldType.kt + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:it visibility:public modality:FINAL [var] + FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Double visibility:private + EXPRESSION_BODY + CONST Double type=kotlin.Double value=3.14 + FUN name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:it visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + CALL 'public open fun toInt (): kotlin.Int declared in kotlin.Double' type=kotlin.Int origin=null + $this: CALL 'public final fun plus (other: kotlin.Int): kotlin.Double [operator] declared in kotlin.Double' type=kotlin.Double origin=PLUS + $this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Double visibility:private' type=kotlin.Double origin=GET_PROPERTY + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + other: CONST Int type=kotlin.Int value=10 + FUN name: visibility:public modality:FINAL <> ($this:.A, value:kotlin.Int) returnType:kotlin.Unit + correspondingProperty: PROPERTY name:it visibility:public modality:FINAL [var] + $this: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:value index:0 type:kotlin.Int + BLOCK_BODY + SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Double visibility:private' type=kotlin.Unit origin=EQ + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + value: CALL 'public open fun toDouble (): kotlin.Double declared in kotlin.Int' type=kotlin.Double origin=null + $this: CALL 'public final fun minus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=MINUS + $this: GET_VAR 'value: kotlin.Int declared in .A.' type=kotlin.Int origin=null + other: CONST Int type=kotlin.Int value=10 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:a type:.A [val] + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + VAR name:it type:kotlin.Int [val] + CALL 'public final fun and (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null + $this: CALL 'public final fun (): kotlin.Int declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=10 + CALL 'public final fun (value: kotlin.Int): kotlin.Unit declared in .A' type=kotlin.Unit origin=EQ + $this: GET_VAR 'val a: .A [val] declared in .test' type=.A origin=null + value: GET_VAR 'val it: kotlin.Int [val] declared in .test' type=kotlin.Int origin=null diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt new file mode 100644 index 00000000000..e5ae473aac2 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +class A { + val it: Number + field = 4 + + fun test() = it + 3 + + val p = 5 + get() = field +} + +fun test() { + val d = test() + val b = A().p + 2 +} diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt.txt new file mode 100644 index 00000000000..77083eb498e --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt.txt @@ -0,0 +1,28 @@ +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + val it: Int + field = 4 + get + + fun test(): Int { + return .().plus(other = 3) + } + + val p: Int + field = 5 + get(): Int { + return .#p + } + +} + +fun test() { + val d: Unit = test() + val b: Int = A().().plus(other = 2) +} + diff --git a/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.txt b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.txt new file mode 100644 index 00000000000..aaf1b069780 --- /dev/null +++ b/compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.txt @@ -0,0 +1,59 @@ +FILE fqName: fileName:/propertyTypeNarrowing.kt + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:it visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=4 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Number + correspondingProperty: PROPERTY name:it visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Number declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:it type:kotlin.Int visibility:private [final]' type=kotlin.Number origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + FUN name:test visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in .A' + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Number declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR ': .A declared in .A.test' type=.A origin=null + other: CONST Int type=kotlin.Int value=3 + PROPERTY name:p visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=5 + FUN name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:p visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=GET_PROPERTY + receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + VAR name:d type:kotlin.Unit [val] + CALL 'public final fun test (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + VAR name:b type:kotlin.Int [val] + CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS + $this: CALL 'public final fun (): kotlin.Int declared in .A' type=kotlin.Int origin=GET_PROPERTY + $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + other: CONST Int type=kotlin.Int value=2 diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java new file mode 100644 index 00000000000..757c45ee3c7 --- /dev/null +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/Fir2IrSpecificBytecodeListingTestGenerated.java @@ -0,0 +1,33 @@ +/* + * 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.test.runners.codegen; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/fir/fir2ir/testData/codegen/bytecodeListing") +@TestDataPath("$PROJECT_ROOT") +public class Fir2IrSpecificBytecodeListingTestGenerated extends AbstractFirBytecodeListingTest { + @Test + public void testAllFilesPresentInBytecodeListing() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/bytecodeListing"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("explicitBackingFieldsInJava.kt") + public void testExplicitBackingFieldsInJava() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/bytecodeListing/explicitBackingFieldsInJava.kt"); + } +} diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java index a69096ed878..24af90a26d0 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirSpecificBlackBoxCodegenTestGenerated.java @@ -17,17 +17,142 @@ import java.util.regex.Pattern; /** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("compiler/fir/fir2ir/testData/codegen/box") -@TestDataPath("$PROJECT_ROOT") public class FirSpecificBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenTest { - @Test - public void testAllFilesPresentInBox() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/box") + @TestDataPath("$PROJECT_ROOT") + public class Box { + @Test + public void testAllFilesPresentInBox() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("sample.kt") + public void testSample() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/sample.kt"); + } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/box/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/box/properties"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/box/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/box/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("backingFieldVisibility.kt") + public void testBackingFieldVisibility() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/backingFieldVisibility.kt"); + } + + @Test + @TestMetadata("charSequenceWithBackingField1.kt") + public void testCharSequenceWithBackingField1() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField1.kt"); + } + + @Test + @TestMetadata("charSequenceWithBackingField2.kt") + public void testCharSequenceWithBackingField2() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField2.kt"); + } + + @Test + @TestMetadata("charSequenceWithBackingField3.kt") + public void testCharSequenceWithBackingField3() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField3.kt"); + } + + @Test + @TestMetadata("charSequenceWithBackingField4.kt") + public void testCharSequenceWithBackingField4() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField4.kt"); + } + + @Test + @TestMetadata("charSequenceWithBackingField5.kt") + public void testCharSequenceWithBackingField5() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/charSequenceWithBackingField5.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldInAnonymous.kt") + public void testExplicitBackingFieldInAnonymous() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/explicitBackingFieldInAnonymous.kt"); + } + + @Test + @TestMetadata("getterReturnTypeWithBackingField.kt") + public void testGetterReturnTypeWithBackingField() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/getterReturnTypeWithBackingField.kt"); + } + + @Test + @TestMetadata("independentBackingFieldType.kt") + public void testIndependentBackingFieldType() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/independentBackingFieldType.kt"); + } + + @Test + @TestMetadata("lateinitBackingFields.kt") + public void testLateinitBackingFields() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/lateinitBackingFields.kt"); + } + + @Test + @TestMetadata("overriddenPropertiesWithExplicitBackingFields.kt") + public void testOverriddenPropertiesWithExplicitBackingFields() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/box/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt"); + } + } + } } - @Test - @TestMetadata("sample.kt") - public void testSample() throws Exception { - runTest("compiler/fir/fir2ir/testData/codegen/box/sample.kt"); + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/boxWithStdLib") + @TestDataPath("$PROJECT_ROOT") + public class BoxWithStdLib { + @Test + public void testAllFilesPresentInBoxWithStdLib() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/boxWithStdLib"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("backingFieldWithSmartTypeParameters.kt") + public void testBackingFieldWithSmartTypeParameters() throws Exception { + runTest("compiler/fir/fir2ir/testData/codegen/boxWithStdLib/properties/backingField/backingFieldWithSmartTypeParameters.kt"); + } + } + } } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrSpecificTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrSpecificTextTestGenerated.java index 0a1a83005a0..d901d250764 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrSpecificTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrSpecificTextTestGenerated.java @@ -30,4 +30,48 @@ public class Fir2IrSpecificTextTestGenerated extends AbstractFir2IrTextTest { public void testSample() throws Exception { runTest("compiler/fir/fir2ir/testData/ir/irText/sample.kt"); } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/ir/irText/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/ir/irText/properties"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Nested + @TestMetadata("compiler/fir/fir2ir/testData/ir/irText/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/fir2ir/testData/ir/irText/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("backingFieldVisibility.kt") + public void testBackingFieldVisibility() throws Exception { + runTest("compiler/fir/fir2ir/testData/ir/irText/properties/backingField/backingFieldVisibility.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldType.kt") + public void testExplicitBackingFieldType() throws Exception { + runTest("compiler/fir/fir2ir/testData/ir/irText/properties/backingField/explicitBackingFieldType.kt"); + } + + @Test + @TestMetadata("independentBackingFieldType.kt") + public void testIndependentBackingFieldType() throws Exception { + runTest("compiler/fir/fir2ir/testData/ir/irText/properties/backingField/independentBackingFieldType.kt"); + } + + @Test + @TestMetadata("propertyTypeNarrowing.kt") + public void testPropertyTypeNarrowing() throws Exception { + runTest("compiler/fir/fir2ir/testData/ir/irText/properties/backingField/propertyTypeNarrowing.kt"); + } + } + } } diff --git a/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.fir.kt b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.fir.kt new file mode 100644 index 00000000000..c1652b91c08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.fir.kt @@ -0,0 +1,4 @@ +class A { + val number: Number + field = 1 +} diff --git a/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt new file mode 100644 index 00000000000..8e659711aef --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt @@ -0,0 +1,4 @@ +class A { + val number: Number + field = 1 +} diff --git a/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.txt b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.txt new file mode 100644 index 00000000000..4ae91ff254b --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.txt @@ -0,0 +1,9 @@ +package + +public final class A { + public constructor A() + public final val number: kotlin.Number + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/psi/propertyBackingField/explicitBackingField.txt b/compiler/testData/psi/propertyBackingField/explicitBackingField.txt index ba63d82cbf8..088f52f17ef 100644 --- a/compiler/testData/psi/propertyBackingField/explicitBackingField.txt +++ b/compiler/testData/psi/propertyBackingField/explicitBackingField.txt @@ -197,17 +197,22 @@ KtFile: explicitBackingField.kt PsiWhiteSpace('\n ') BACKING_FIELD PsiElement(field)('field') - PsiWhiteSpace(' ') - BLOCK - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - RETURN - PsiElement(return)('return') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('10') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') + PsiErrorElement:Property getter or setter expected + + PsiWhiteSpace(' ') + FUN + PsiErrorElement:Expecting a top level declaration + + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('10') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') PROPERTY PsiElement(val)('val') diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index de0f9f70f7e..027e2642316 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -22491,6 +22491,22 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.kt"); } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties/backingField"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("trivialExplicitBackingFIeld.kt") + public void testTrivialExplicitBackingFIeld() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt index 434ff712587..66a2480d168 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.builders.configureFirHandlersStep import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING +import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives.WITH_STDLIB import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade import org.jetbrains.kotlin.test.frontend.fir.FirMetaInfoDiffSuppressor @@ -43,6 +44,12 @@ open class AbstractFirBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase) { suiteTestClassName = "FirSpecificBlackBoxCodegenTestGenerated" ) { model("codegen/box") + model("codegen/boxWithStdLib") } testClass( diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 7ca3341faad..2c8d7c30b76 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5532,6 +5532,104 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis } } + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties") + @TestDataPath("$PROJECT_ROOT") + public class Properties { + @Test + public void testAllFilesPresentInProperties() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("backingFieldModifiers.kt") + public void testBackingFieldModifiers() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldModifiers.kt"); + } + + @Test + @TestMetadata("backingFieldVisibility.kt") + public void testBackingFieldVisibility() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldVisibility.kt"); + } + + @Test + @TestMetadata("backingFieldWithSmartTypeParameters.kt") + public void testBackingFieldWithSmartTypeParameters() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/backingFieldWithSmartTypeParameters.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldInInterface.kt") + public void testExplicitBackingFieldInInterface() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldInInterface.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldType.kt") + public void testExplicitBackingFieldType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldType.kt"); + } + + @Test + @TestMetadata("explicitBackingFieldsWithDelegates.kt") + public void testExplicitBackingFieldsWithDelegates() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/explicitBackingFieldsWithDelegates.kt"); + } + + @Test + @TestMetadata("filePrivateBackingFieldAccess.kt") + public void testFilePrivateBackingFieldAccess() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/filePrivateBackingFieldAccess.kt"); + } + + @Test + @TestMetadata("lateinitBackingFields.kt") + public void testLateinitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/lateinitBackingFields.kt"); + } + + @Test + @TestMetadata("localVariablesWithBackingFields.kt") + public void testLocalVariablesWithBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/localVariablesWithBackingFields.kt"); + } + + @Test + @TestMetadata("overriddenPropertiesWithExplicitBackingFields.kt") + public void testOverriddenPropertiesWithExplicitBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/overriddenPropertiesWithExplicitBackingFields.kt"); + } + + @Test + @TestMetadata("propertyTypeNarrowing.kt") + public void testPropertyTypeNarrowing() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/propertyTypeNarrowing.kt"); + } + + @Test + @TestMetadata("randomWeirdBackingFields.kt") + public void testRandomWeirdBackingFields() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/randomWeirdBackingFields.kt"); + } + + @Test + @TestMetadata("redundantExplicitBackingField.kt") + public void testRedundantExplicitBackingField() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); + } + } + } + @Nested @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations") @TestDataPath("$PROJECT_ROOT") diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 46c8bf15aca..205581b6988 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -22485,6 +22485,22 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/properties/lateinitOnTopLevel.kt"); } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/properties/backingField") + @TestDataPath("$PROJECT_ROOT") + public class BackingField { + @Test + public void testAllFilesPresentInBackingField() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/properties/backingField"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("trivialExplicitBackingFIeld.kt") + public void testTrivialExplicitBackingFIeld() throws Exception { + runTest("compiler/testData/diagnostics/tests/properties/backingField/trivialExplicitBackingFIeld.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters") @TestDataPath("$PROJECT_ROOT")