Add a test for data flow with reassignments in local classes
This commit is contained in:
+6
@@ -30901,6 +30901,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectMembers.kt")
|
||||
public void testObjectMembers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/objectMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("property.kt")
|
||||
public void testProperty() throws Exception {
|
||||
|
||||
+6
@@ -30997,6 +30997,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectMembers.kt")
|
||||
public void testObjectMembers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/objectMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("property.kt")
|
||||
public void testProperty() throws Exception {
|
||||
|
||||
+6
@@ -30901,6 +30901,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectMembers.kt")
|
||||
public void testObjectMembers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/objectMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("property.kt")
|
||||
public void testProperty() throws Exception {
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
// SKIP_TXT
|
||||
|
||||
fun objectInit() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
x.length // ok
|
||||
y.length // ok
|
||||
val o = object {
|
||||
init { x.length } // ?
|
||||
init { x = null }
|
||||
init { x.length } // bad
|
||||
init { y.length } // ok
|
||||
fun foo() = x.length // bad
|
||||
}
|
||||
y = null
|
||||
x<!UNSAFE_CALL!>.<!>length // bad
|
||||
if (<!SENSELESS_COMPARISON!>x != null<!>) x.length // ok
|
||||
}
|
||||
|
||||
fun objectMethod() {
|
||||
var x: String?
|
||||
x = ""
|
||||
x.length // ok
|
||||
val o = object {
|
||||
init { x.length } // sort of bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
fun bar() { x = null }
|
||||
fun baz() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
o.bar() // assign here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun classInit() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
x.length // ok
|
||||
y.length // ok
|
||||
val ctor = run {
|
||||
class C {
|
||||
init { x.length } // ?
|
||||
init { x = null }
|
||||
init { x.length } // bad
|
||||
init { y.length } // bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
x.length // bad
|
||||
if (<!SENSELESS_COMPARISON!>x != null<!>) {
|
||||
y = null
|
||||
C() // read y & assign x here
|
||||
x.length // bad
|
||||
}
|
||||
::C
|
||||
}
|
||||
x.length // bad
|
||||
if (<!SENSELESS_COMPARISON!>x != null<!>) {
|
||||
ctor() // read y & assign x here
|
||||
x.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun classMethod() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
x.length // ok
|
||||
y.length // ok
|
||||
val ctor = run {
|
||||
class C {
|
||||
init { x.length } // sort of bad
|
||||
init { y.length } // bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
fun bar() { x = null }
|
||||
fun baz() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
C().bar() // assign here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
::C
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
y = null
|
||||
ctor().bar() // read y & assign x here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun runInInverseOrder(x: Any?, a: () -> Unit, b: () -> Unit) {
|
||||
b()
|
||||
a()
|
||||
}
|
||||
|
||||
fun objectInParallelLambda() {
|
||||
var x: String?
|
||||
x = ""
|
||||
runInInverseOrder(
|
||||
object { init { x.length } }, // ok
|
||||
{ object { init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } } }, // bad
|
||||
{ x = null },
|
||||
)
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// SKIP_TXT
|
||||
|
||||
fun objectInit() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length // ok
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.length // ok
|
||||
val o = object {
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // ?
|
||||
init { x = null }
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // bad
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>y<!>.length } // ok
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
y = null
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) <!SMARTCAST_IMPOSSIBLE!>x<!>.length // ok
|
||||
}
|
||||
|
||||
fun objectMethod() {
|
||||
var x: String?
|
||||
x = ""
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length // ok
|
||||
val o = object {
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // sort of bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
fun bar() { x = null }
|
||||
fun baz() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
o.bar() // assign here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun classInit() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length // ok
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.length // ok
|
||||
val ctor = run {
|
||||
class C {
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // ?
|
||||
init { x = null }
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // bad
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>y<!>.length } // bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
y = null
|
||||
C() // read y & assign x here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
::C
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
ctor() // read y & assign x here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun classMethod() {
|
||||
var x: String?
|
||||
var y: String?
|
||||
x = ""
|
||||
y = ""
|
||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length // ok
|
||||
<!DEBUG_INFO_SMARTCAST!>y<!>.length // ok
|
||||
val ctor = run {
|
||||
class C {
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // sort of bad
|
||||
init { <!SMARTCAST_IMPOSSIBLE!>y<!>.length } // bad
|
||||
fun foo() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
fun bar() { x = null }
|
||||
fun baz() = <!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
C().bar() // assign here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
::C
|
||||
}
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
if (x != null) {
|
||||
y = null
|
||||
ctor().bar() // read y & assign x here
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
}
|
||||
|
||||
fun runInInverseOrder(x: Any?, a: () -> Unit, b: () -> Unit) {
|
||||
b()
|
||||
a()
|
||||
}
|
||||
|
||||
fun objectInParallelLambda() {
|
||||
var x: String?
|
||||
x = ""
|
||||
runInInverseOrder(
|
||||
object { init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } }, // ok
|
||||
{ object { init { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } } }, // bad
|
||||
{ x = null },
|
||||
)
|
||||
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // bad
|
||||
}
|
||||
Generated
+6
@@ -30997,6 +30997,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/lambdaBetweenArguments.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectMembers.kt")
|
||||
public void testObjectMembers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/variables/objectMembers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("property.kt")
|
||||
public void testProperty() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user