Differ this/non-this instances for vars initialization in class

When deal with constructed object (not this) treat it like it's fully initialized.

Otherwise (this or access with no receiver) access instruction
should be handled as it was before.

 #KT-6788 Fixed
 #KT-4126 Fixed
This commit is contained in:
Denis Zharkov
2015-02-17 10:23:07 +03:00
parent 1004e016fd
commit 7d963e8e07
17 changed files with 300 additions and 50 deletions
@@ -0,0 +1,3 @@
public data class ProductGroup(val short_name: String, val parent: ProductGroup?) {
val name: String = if (parent == null) short_name else "${<!DEBUG_INFO_SMARTCAST!>parent<!>.name} $short_name"
}
@@ -0,0 +1,14 @@
package
kotlin.data() public final class ProductGroup {
public constructor ProductGroup(/*0*/ short_name: kotlin.String, /*1*/ parent: ProductGroup?)
internal final val name: kotlin.String
internal final val parent: ProductGroup?
internal final val short_name: kotlin.String
internal final /*synthesized*/ fun component1(): kotlin.String
internal final /*synthesized*/ fun component2(): ProductGroup?
public final /*synthesized*/ fun copy(/*0*/ short_name: kotlin.String = ..., /*1*/ parent: ProductGroup? = ...): ProductGroup
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
}
@@ -0,0 +1,10 @@
class A(val next: A? = null) {
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val x: String<!>
init {
<!VAL_REASSIGNMENT!>next?.x<!> = "a"
}
}
class B(val next: B? = null) {
var x: String = next?.x ?: "default" // it's ok to use `x` of next
}
@@ -0,0 +1,19 @@
package
internal final class A {
public constructor A(/*0*/ next: A? = ...)
internal final val next: A?
internal final val x: kotlin.String
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
}
internal final class B {
public constructor B(/*0*/ next: B? = ...)
internal final val next: B?
internal final var x: kotlin.String
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
}
@@ -0,0 +1,12 @@
class A(val next: A? = null) {
val x: String
init {
<!VAL_REASSIGNMENT!>next?.x<!> = "a"
x = "b"
<!VAL_REASSIGNMENT!>this.x<!> = "c"
x = "d" // don't repeat the same diagnostic again with this receiver
this.x = "e"
<!VAL_REASSIGNMENT!>next?.x<!> = "f"
}
}
@@ -0,0 +1,10 @@
package
internal final class A {
public constructor A(/*0*/ next: A? = ...)
internal final val next: A?
internal final val x: kotlin.String
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
}
@@ -0,0 +1,21 @@
class Outer {
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>val outerProp: String<!>
inner class Inner(inner: Inner, outer: Outer) {
val innerProp: String
init {
outerProp // use of outerProp is ok because we're suppose that Outer instance should be initialized
this@Outer.outerProp
<!VAL_REASSIGNMENT!>this@Outer.outerProp<!> = "1"
outerProp = "2" // do not repeat the same diagnostic with this receiver of outer class
<!VAL_REASSIGNMENT!>outer.outerProp<!> = "3"
innerProp = "4" + inner.innerProp
<!VAL_REASSIGNMENT!>this@Inner.innerProp<!> = "5"
innerProp = "6" // do not repeat the same diagnostic with this receiver
this@Inner.innerProp = "7"
<!VAL_REASSIGNMENT!>inner.innerProp<!> = "8"
}
}
}
@@ -0,0 +1,17 @@
package
internal final class Outer {
public constructor Outer()
internal final val outerProp: kotlin.String
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
internal final inner class Inner {
public constructor Inner(/*0*/ inner: Outer.Inner, /*1*/ outer: Outer)
internal final val innerProp: kotlin.String
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
}
}
@@ -0,0 +1,12 @@
class A(val next: A? = null) {
val x: String
init {
<!VAL_REASSIGNMENT!>next?.x<!> = "a"
this@A.x = "b"
<!VAL_REASSIGNMENT!>this.x<!> = "c"
x = "d" // don't repeat the same diagnostic again with this receiver
this@A.x = "e"
<!VAL_REASSIGNMENT!>next?.x<!> = "f"
}
}
@@ -0,0 +1,10 @@
package
internal final class A {
public constructor A(/*0*/ next: A? = ...)
internal final val next: A?
internal final val x: kotlin.String
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
}
@@ -0,0 +1,15 @@
class A {
val x: Int
val y: Int
constructor(x: Int, y: Int) {
this.x = x
this.y = y
}
constructor(other: A) {
x = other.x
y = other.y
}
}
class A1(val x: Int, val y: Int) {
constructor(other: A1): this(other.x, other.y) {}
}
@@ -0,0 +1,21 @@
package
internal final class A {
public constructor A(/*0*/ other: A)
public constructor A(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
internal final val x: kotlin.Int
internal final val y: kotlin.Int
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
}
internal final class A1 {
public constructor A1(/*0*/ other: A1)
public constructor A1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
internal final val x: kotlin.Int
internal final val y: kotlin.Int
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
}