[FIX] Add some more tests
diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.fir.txt new file mode 100644 index 0000000..eca620c --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.fir.txt
@@ -0,0 +1,53 @@ +FILE: untypedPropertyWithBackingFieldUsage.kt + public final val simpleNoTypeBlock: <ERROR TYPE REF: Unresolved name: field> + public get(): <ERROR TYPE REF: Unresolved name: field> { + ^ <Unresolved name: field># + } + public final val simpleNoTypeExpression: <ERROR TYPE REF: Unresolved name: field> + public get(): <ERROR TYPE REF: Unresolved name: field> { + ^ <Unresolved name: field># + } + public final val simpleTypeBlock: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ F|/simpleTypeBlock| + } + public final val simpleTypeExpression: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ F|/simpleTypeExpression| + } + public final val withFieldNoTypeBlock: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ <Unresolved name: field>#.R|kotlin/text/toInt|() + } + public final val withFieldNoTypeExpression: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ <Unresolved name: field>#.R|kotlin/text/toInt|() + } + public final val withFieldTypeBlock: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ F|/withFieldTypeBlock|.R|kotlin/Double.toInt|() + } + public final val withFieldTypeExpression: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ F|/withFieldTypeExpression|.R|kotlin/Double.toInt|() + } + public final val minimalFieldWithInitializer: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> + public get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> + public final val minimalFieldWithNoInitializer: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> + public get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> + public final val constWithFieldNoTypeBlock: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(10) + } + public final val constWithFieldNoTypeExpression: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(10) + } + public final val constWithFieldTypeBlock: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(10) + } + public final val constWithFieldTypeExpression: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(10) + }
diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt new file mode 100644 index 0000000..02bee41 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt
@@ -0,0 +1,63 @@ +val simpleNoTypeBlock + get() { + return <!UNRESOLVED_REFERENCE!>field<!> + } + +val simpleNoTypeExpression + get() = <!UNRESOLVED_REFERENCE!>field<!> + +<!MUST_BE_INITIALIZED!>val simpleTypeBlock: Int<!> + get() { + return field + } + +<!MUST_BE_INITIALIZED!>val simpleTypeExpression: Int<!> + get() = field + +val withFieldNoTypeBlock + field = 3.14 + get() { + // *TODO: add support for this? + return <!UNRESOLVED_REFERENCE!>field<!>.toInt() + } + +val withFieldNoTypeExpression + field = 3.14 + get() = <!UNRESOLVED_REFERENCE!>field<!>.toInt() + +val withFieldTypeBlock: Int + field = 3.14 + get() { + return field.toInt() + } + +val withFieldTypeExpression: Int + field = 3.14 + get() = field.toInt() + +// If * is supported, this is a relevant message +// since adding a getter _may_ be enough +<!PROPERTY_MUST_HAVE_GETTER!>val minimalFieldWithInitializer + field = 1<!> + +<!PROPERTY_MUST_HAVE_GETTER!>val minimalFieldWithNoInitializer + <!PROPERTY_FIELD_DECLARATION_MISSING_INITIALIZER!>field: Int<!><!> + +// TODO: redundant backing field? +// Or we assume someone may still want +// to access it directly via `myProperty#field`? +val constWithFieldNoTypeBlock + field = 3.14 + get() = 10 + +val constWithFieldNoTypeExpression + field = 3.14 + get() = 10 + +val constWithFieldTypeBlock: Int + field = 3.14 + get() = 10 + +val constWithFieldTypeExpression: Int + field = 3.14 + get() = 10
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 d585f74..ade35c0 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
@@ -5627,6 +5627,12 @@ public void testRedundantExplicitBackingField() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); } + + @Test + @TestMetadata("untypedPropertyWithBackingFieldUsage.kt") + public void testUntypedPropertyWithBackingFieldUsage() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt"); + } } }
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 52fbd46..970ae4c 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
@@ -5627,6 +5627,12 @@ public void testRedundantExplicitBackingField() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); } + + @Test + @TestMetadata("untypedPropertyWithBackingFieldUsage.kt") + public void testUntypedPropertyWithBackingFieldUsage() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt"); + } } }
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 2c8d7c30..6842de1 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
@@ -5627,6 +5627,12 @@ public void testRedundantExplicitBackingField() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/redundantExplicitBackingField.kt"); } + + @Test + @TestMetadata("untypedPropertyWithBackingFieldUsage.kt") + public void testUntypedPropertyWithBackingFieldUsage() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/properties/backingField/untypedPropertyWithBackingFieldUsage.kt"); + } } }