Take imported from object descriptor into account in pseudocode

So #KT-15566 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-04-21 16:57:39 +03:00
committed by Mikhail Glukhikh
parent 056eebf69c
commit 14e798a1fc
4 changed files with 104 additions and 1 deletions
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.KtElement;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.PropertyImportedFromObject;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.ResolvedCallUtilKt;
import org.jetbrains.kotlin.types.KotlinType;
@@ -98,7 +99,12 @@ public class PseudocodeUtil {
) {
if (instruction instanceof AccessValueInstruction) {
KtElement element = ((AccessValueInstruction) instruction).getElement();
return element instanceof KtDeclaration ? null : extractVariableDescriptorIfAny(instruction, bindingContext);
if (element instanceof KtDeclaration) return null;
VariableDescriptor descriptor = extractVariableDescriptorIfAny(instruction, bindingContext);
if (descriptor instanceof PropertyImportedFromObject) {
return ((PropertyImportedFromObject) descriptor).getCallableFromObject();
}
return descriptor;
}
return null;
}
@@ -0,0 +1,35 @@
// See KT-15566
import DefaultHttpClient.client
interface HttpClient
class HttpClientImpl : HttpClient
// Below we should have initialization error for both (!) delegates
object DefaultHttpClient : HttpClient by <!UNINITIALIZED_VARIABLE!>client<!> {
val client = HttpClientImpl()
}
object DefaultHttpClientWithGetter : HttpClient by client {
val client get() = HttpClientImpl()
}
object DefaultHttpClientWithFun : HttpClient by fClient() {
}
private fun fClient() = HttpClientImpl()
private fun <T> lazy(init: () -> T): kotlin.<!UNRESOLVED_REFERENCE!>Lazy<!><T> {
init()
null!!
}
object DefaultHttpClientWithBy : HttpClient by client {
val client by lazy { HttpClientImpl() }
}
object DefaultFqHttpClient : HttpClient by DefaultFqHttpClient.<!UNINITIALIZED_VARIABLE!>client<!> {
val client = HttpClientImpl()
}
@@ -0,0 +1,56 @@
package
private fun fClient(): HttpClientImpl
private fun </*0*/ T> lazy(/*0*/ init: () -> T): [ERROR : kotlin.Lazy<T>]<T>
public object DefaultFqHttpClient : HttpClient {
private constructor DefaultFqHttpClient()
public final val client: HttpClientImpl
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
}
public object DefaultHttpClient : HttpClient {
private constructor DefaultHttpClient()
public final val client: HttpClientImpl
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
}
public object DefaultHttpClientWithBy : HttpClient {
private constructor DefaultHttpClientWithBy()
public final val client: [ERROR : <ERROR FUNCTION RETURN TYPE>]
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
}
public object DefaultHttpClientWithFun : HttpClient {
private constructor DefaultHttpClientWithFun()
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
}
public object DefaultHttpClientWithGetter : HttpClient {
private constructor DefaultHttpClientWithGetter()
public final val client: HttpClientImpl
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
}
public interface HttpClient {
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
}
public final class HttpClientImpl : HttpClient {
public constructor HttpClientImpl()
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
}
@@ -3748,6 +3748,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("fieldAsClassDelegate.kt")
public void testFieldAsClassDelegate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.kt");
doTest(fileName);
}
@TestMetadata("infiniteLoops.kt")
public void testInfiniteLoops() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/infiniteLoops.kt");