Do not resolve all bodies of anonymous objects and local classes in partial body resolve

This commit is contained in:
Valentin Kipyatkov
2016-10-28 22:12:13 +03:00
parent 23c22984e8
commit c0d89e67a9
11 changed files with 80 additions and 27 deletions
@@ -106,6 +106,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
platform: TargetPlatform,
lookupTracker: LookupTracker,
languageVersionSettings: LanguageVersionSettings,
statementFilter: StatementFilter,
localClassDescriptorHolder: LocalClassDescriptorHolder
): StorageComponentContainer = createContainer("LocalClassifierAnalyzer", platform) {
configureModule(moduleContext, platform, bindingTrace)
@@ -125,6 +126,7 @@ fun createContainerForLazyLocalClassifierAnalyzer(
useImpl<LocalLazyDeclarationResolver>()
useInstance(languageVersionSettings)
useInstance(statementFilter)
}
fun createContainerForLazyResolve(
@@ -35,7 +35,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull DataFlowInfo dataFlowInfo,
@NotNull KotlinType expectedType
) {
return newContext(trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT);
return newContext(trace, scope, dataFlowInfo, expectedType, ContextDependency.INDEPENDENT, StatementFilter.NONE);
}
@NotNull
@@ -44,11 +44,11 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull KotlinType expectedType,
@NotNull ContextDependency contextDependency
@NotNull ContextDependency contextDependency,
@NotNull StatementFilter statementFilter
) {
return newContext(trace, scope, dataFlowInfo, expectedType,
contextDependency, new ResolutionResultsCacheImpl(),
StatementFilter.NONE, false);
return newContext(trace, scope, dataFlowInfo, expectedType, contextDependency,
new ResolutionResultsCacheImpl(), statementFilter, false);
}
@NotNull
@@ -106,7 +106,7 @@ public class ExpressionTypingServices {
@NotNull ContextDependency contextDependency
) {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, scope, dataFlowInfo, expectedType, contextDependency
trace, scope, dataFlowInfo, expectedType, contextDependency, statementFilter
);
if (contextExpression != expression) {
context = context.replaceExpressionContextProvider(new Function1<KtExpression, KtExpression>() {
@@ -52,7 +52,7 @@ class LocalClassifierAnalyzer(
private val globalContext: GlobalContext,
private val storageManager: StorageManager,
private val descriptorResolver: DescriptorResolver,
private val funcionDescriptorResolver: FunctionDescriptorResolver,
private val functionDescriptorResolver: FunctionDescriptorResolver,
private val typeResolver: TypeResolver,
private val annotationResolver: AnnotationResolver,
private val platform: TargetPlatform,
@@ -74,6 +74,7 @@ class LocalClassifierAnalyzer(
platform,
lookupTracker,
languageVersionSettings,
context.statementFilter,
LocalClassDescriptorHolder(
scope,
classOrObject,
@@ -82,7 +83,7 @@ class LocalClassifierAnalyzer(
context,
module,
descriptorResolver,
funcionDescriptorResolver,
functionDescriptorResolver,
typeResolver,
annotationResolver,
supertypeLoopChecker,
@@ -7,18 +7,18 @@ open class C(p: Int) {
fun foo(p: String?) {
val o = object : Runnable {
override fun run() {
if (p == null) return
print(p.size)
/* STATEMENT DELETED: if (p == null) return */
/* STATEMENT DELETED: print(p.length) */
}
}
val c = object : C(p!!.size) {
override fun f() {
super.f()
if (p == null) return
print(p.size)
/* STATEMENT DELETED: super.f() */
/* STATEMENT DELETED: if (p == null) return */
/* STATEMENT DELETED: print(p.length) */
}
}
<caret>p?.size
}
<caret>p?.length
}
@@ -5,15 +5,15 @@ open class C(p: Int) {
}
fun foo(p: String?) {
/* STATEMENT DELETED: val o = object : Runnable { override fun run() { if (p == null) return print(p.size) } } */
/* STATEMENT DELETED: val o = object : Runnable { override fun run() { if (p == null) return print(p.length) } } */
val c = object : C(p!!.size) {
override fun f() {
super.f()
if (p == null) return
print(p.size)
/* STATEMENT DELETED: super.f() */
/* STATEMENT DELETED: if (p == null) return */
/* STATEMENT DELETED: print(p.length) */
}
}
<caret>p?.size
}
<caret>p?.length
}
@@ -6,7 +6,7 @@ fun foo(p: String?) {
val o = object : Runnable {
override fun run() {
if (p == null) return
print(p.size)
print(p.length)
}
}
@@ -14,9 +14,9 @@ fun foo(p: String?) {
override fun f() {
super.f()
if (p == null) return
print(p.size)
print(p.length)
}
}
<caret>p?.size
<caret>p?.length
}
@@ -0,0 +1,23 @@
Resolve target: val length: kotlin.Int
----------------------------------------------
open class C(p: Int) {
open fun f(){}
}
fun foo(p1: String?, p2: String?) {
if (p1 == null) return
/* STATEMENT DELETED: println(p1) */
val c = object : C(p1.length) {
override fun f() {
/* STATEMENT DELETED: super.f() */
if (p2 == null) return
print(p2.<caret>length)
/* STATEMENT DELETED: bar() */
}
fun bar() {
/* STATEMENT DELETED: print(1) */
}
}
}
@@ -0,0 +1,21 @@
open class C(p: Int) {
open fun f(){}
}
fun foo(p1: String?, p2: String?) {
if (p1 == null) return
println(p1)
val c = object : C(p1.length) {
override fun f() {
super.f()
if (p2 == null) return
print(p2.<caret>length)
bar()
}
fun bar() {
print(1)
}
}
}
@@ -3,9 +3,9 @@ Resolve target: value-parameter p: kotlin.String?
fun foo(p: String?) {
class LocalClass {
fun f(): String? {
if (p == null) return null
print(p.size)
return ""
/* STATEMENT DELETED: if (p == null) return null */
/* STATEMENT DELETED: print(p.size) */
/* STATEMENT DELETED: return "" */
}
}
@@ -317,6 +317,12 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
doTest(fileName);
}
@TestMetadata("InsideAnonymousObject.kt")
public void testInsideAnonymousObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/InsideAnonymousObject.kt");
doTest(fileName);
}
@TestMetadata("IntConstantTypeBug.kt")
public void testIntConstantTypeBug() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IntConstantTypeBug.kt");