Report UNINITIALIZED_VARIABLE also for qualified object property #KT-12809 Fixed

(cherry picked from commit 7b2857f)
This commit is contained in:
Mikhail Glukhikh
2016-08-05 13:24:52 +03:00
committed by Mikhail Glukhikh
parent 35446037bb
commit 0c98231f53
7 changed files with 92 additions and 1 deletions
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.descriptorUtil.getOwnerForEffectiveDispatchReceiverParameter
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassValueReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
@@ -50,6 +51,9 @@ fun ResolvedCall<*>.hasThisOrNoDispatchReceiver(
// foo() -- implicit receiver
dispatchReceiverDescriptor = dispatchReceiverValue.declarationDescriptor
}
else if (dispatchReceiverValue is ClassValueReceiver) {
dispatchReceiverDescriptor = dispatchReceiverValue.classQualifier.descriptor
}
else if (dispatchReceiverValue is ExpressionReceiver) {
val expression = KtPsiUtil.deparenthesize(dispatchReceiverValue.expression)
if (expression is KtThisExpression) {
@@ -0,0 +1,8 @@
// See KT-12809
open class A(val a: Any) {
override fun toString() = a.toString()
}
object B : A(B.<!UNINITIALIZED_VARIABLE!>foo<!>) { // call B.foo should be not-allowed
val foo = 4
}
@@ -0,0 +1,18 @@
package
public open class A {
public constructor A(/*0*/ a: kotlin.Any)
public final val a: kotlin.Any
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*/ fun toString(): kotlin.String
}
public object B : A {
private constructor B()
public final override /*1*/ /*fake_override*/ val a: kotlin.Any
public final val foo: kotlin.Int = 4
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
}
@@ -29,7 +29,7 @@ enum class D(val x: Int) {
}
enum class E(val v: Int) {
E1(Nested.COPY);
E1(Nested.<!UNINITIALIZED_VARIABLE!>COPY<!>);
object Nested {
val COPY = E1.v
@@ -0,0 +1,16 @@
object O {
// This is correct, foo is the same
tailrec fun foo(i: Int): Int = if (i < 0) 0 else O.foo(i - 1)
}
class A {
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo(i: Int)<!> = if (i < 0) 0 else A.foo(i - 1)
companion object {
fun foo(i: Int) = 42 + i
}
}
class B {
<!NO_TAIL_CALLS_FOUND!>tailrec fun foo(i: Int)<!> = if (i < 0) 0 else O.foo(i - 1)
}
@@ -0,0 +1,33 @@
package
public final class A {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final tailrec fun foo(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final tailrec fun foo(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public object O {
private constructor O()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final tailrec fun foo(/*0*/ i: kotlin.Int): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -685,6 +685,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("tailRecursionComplex.kt")
public void testTailRecursionComplex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/tailRecursionComplex.kt");
doTest(fileName);
}
@TestMetadata("TraitOverrideObjectMethods.kt")
public void testTraitOverrideObjectMethods() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/TraitOverrideObjectMethods.kt");
@@ -3252,6 +3258,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("constructorPropertyInterdependence.kt")
public void testConstructorPropertyInterdependence() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/constructorPropertyInterdependence.kt");
doTest(fileName);
}
@TestMetadata("definiteReturnInWhen.kt")
public void testDefiniteReturnInWhen() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.kt");