[FIR] Report VAL_REASSIGNMENT on assign to non-local vals
In this commit reporting on member properties in init section of class is not supported (see KT-55528) ^KT-55493 Fixed
This commit is contained in:
committed by
Space Team
parent
e87a064cdd
commit
02e327277e
+10
@@ -940,6 +940,16 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
public void testInitializationInTry() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/initializationInTry.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reassignOfNonLocalProperty_initializedProperties.kt")
|
||||
public void testReassignOfNonLocalProperty_initializedProperties() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reassignOfNonMemberProperty_lateInitialization.kt")
|
||||
public void testReassignOfNonMemberProperty_lateInitialization() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonMemberProperty_lateInitialization.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/cfg")
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
FILE: reassignOfNonLocalProperty_initializedProperties.kt
|
||||
public final val z: R|kotlin/String| = String(ok)
|
||||
public get(): R|kotlin/String|
|
||||
public final val R|Some|.y: R|kotlin/String|
|
||||
public get(): R|kotlin/String| {
|
||||
^ String(ok)
|
||||
}
|
||||
public final class Some : R|kotlin/Any| {
|
||||
public constructor(): R|Some| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val x: R|kotlin/String| = String(ok)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
init {
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/y| = String(error)
|
||||
R|/z| = String(error)
|
||||
}
|
||||
|
||||
public final val a: R|kotlin/String| = this@R|/Some|.R|kotlin/run|<R|Some|, R|kotlin/String|>(<L> = run@fun R|Some|.<anonymous>(): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
this@R|special/anonymous|.R|/Some.x| = String(error)
|
||||
this@R|special/anonymous|.R|/y| = String(error)
|
||||
R|/z| = String(error)
|
||||
^ String(hello)
|
||||
}
|
||||
)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final fun test_1(): R|kotlin/Unit| {
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/y| = String(error)
|
||||
R|/z| = String(error)
|
||||
}
|
||||
|
||||
}
|
||||
public final fun R|Some|.test_2(): R|kotlin/Unit| {
|
||||
this@R|/test_2|.R|/Some.x| = String(error)
|
||||
this@R|/test_2|.R|/y| = String(error)
|
||||
R|/z| = String(error)
|
||||
}
|
||||
public final fun test_3(some: R|Some|): R|kotlin/Unit| {
|
||||
R|<local>/some|.R|/Some.x| = String(error)
|
||||
R|<local>/some|.R|/y| = String(error)
|
||||
R|/z| = String(error)
|
||||
}
|
||||
compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// ISSUE: KT-55493
|
||||
// WITH_STDLIB
|
||||
|
||||
val z: String = "ok"
|
||||
|
||||
val Some.y: String
|
||||
get() = "ok"
|
||||
|
||||
class Some {
|
||||
val x: String = "ok"
|
||||
|
||||
init {
|
||||
<!VAL_REASSIGNMENT!>x<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>y<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
|
||||
val a: String = run {
|
||||
<!VAL_REASSIGNMENT!>x<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>y<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
"hello"
|
||||
}
|
||||
|
||||
fun test_1() {
|
||||
<!VAL_REASSIGNMENT!>x<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>y<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
}
|
||||
|
||||
fun Some.test_2() {
|
||||
<!VAL_REASSIGNMENT!>x<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>y<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
|
||||
fun test_3(some: Some) {
|
||||
some.<!VAL_REASSIGNMENT!>x<!> = "error"
|
||||
some.<!VAL_REASSIGNMENT!>y<!> = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
FILE: reassignOfNonMemberProperty_lateInitialization.kt
|
||||
public final val R|Some|.z: R|kotlin/String|
|
||||
public get(): R|kotlin/String| {
|
||||
^ String(ok)
|
||||
}
|
||||
public final class Some : R|kotlin/Any| {
|
||||
public constructor(): R|Some| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val x: R|kotlin/String|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final val y: R|kotlin/String|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
init {
|
||||
this@R|/Some|.R|/Some.x| = String(ok)
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/z| = String(error)
|
||||
}
|
||||
|
||||
public final val a: R|kotlin/String| = this@R|/Some|.R|kotlin/run|<R|Some|, R|kotlin/String|>(<L> = run@fun R|Some|.<anonymous>(): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
|
||||
this@R|special/anonymous|.R|/Some.x| = String(error)
|
||||
this@R|special/anonymous|.R|/Some.y| = String(ok)
|
||||
this@R|special/anonymous|.R|/Some.y| = String(error)
|
||||
this@R|special/anonymous|.R|/z| = String(error)
|
||||
^ String(hello)
|
||||
}
|
||||
)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
init {
|
||||
this@R|/Some|.R|/Some.x| = String(error)
|
||||
this@R|/Some|.R|/Some.y| = String(error)
|
||||
this@R|/Some|.R|/z| = String(error)
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// ISSUE: KT-55493
|
||||
// WITH_STDLIB
|
||||
|
||||
val Some.z: String
|
||||
get() = "ok"
|
||||
|
||||
class Some {
|
||||
val x: String
|
||||
val y: String
|
||||
|
||||
init {
|
||||
x = "ok"
|
||||
x = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
|
||||
val a: String = run {
|
||||
x = "error"
|
||||
y = "ok"
|
||||
y = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
"hello"
|
||||
}
|
||||
|
||||
init {
|
||||
x = "error"
|
||||
y = "error"
|
||||
<!VAL_REASSIGNMENT!>z<!> = "error"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ fun main(d1: D1, d2: D2, d3: D3) {
|
||||
d2.bar(1, "").checkType { _<String>() }
|
||||
|
||||
d3.x.checkType { _<String>() }
|
||||
d3.x = ""
|
||||
d3.<!VAL_REASSIGNMENT!>x<!> = ""
|
||||
d3.foo().checkType { _<String?>() }
|
||||
d3.bar(1, "").checkType { _<String?>() }
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ class B(p0: String) {
|
||||
p3 = p1
|
||||
}
|
||||
init {
|
||||
p1 = <!ASSIGNMENT_TYPE_MISMATCH!>p0.length<!>
|
||||
<!VAL_REASSIGNMENT!>p1<!> = <!ASSIGNMENT_TYPE_MISMATCH!>p0.length<!>
|
||||
p3 = ""
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -1086,6 +1086,18 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
public void testInitializationInTry() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/initializationInTry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignOfNonLocalProperty_initializedProperties.kt")
|
||||
public void testReassignOfNonLocalProperty_initializedProperties() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignOfNonMemberProperty_lateInitialization.kt")
|
||||
public void testReassignOfNonMemberProperty_lateInitialization() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonMemberProperty_lateInitialization.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -1086,6 +1086,18 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
public void testInitializationInTry() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/initializationInTry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignOfNonLocalProperty_initializedProperties.kt")
|
||||
public void testReassignOfNonLocalProperty_initializedProperties() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reassignOfNonMemberProperty_lateInitialization.kt")
|
||||
public void testReassignOfNonMemberProperty_lateInitialization() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonMemberProperty_lateInitialization.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user