Correct scope for property accessors in lazy resolve
This commit is contained in:
@@ -161,11 +161,11 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerScope(@Nullable JetDeclaration declaration, @NotNull JetDeclaration anchorForScope) {
|
||||
private void registerScope(@Nullable JetDeclaration declaration) {
|
||||
if (declaration == null) return;
|
||||
c.registerDeclaringScope(
|
||||
declaration,
|
||||
resolveSession.getScopeProvider().getResolutionScopeForDeclaration(anchorForScope)
|
||||
resolveSession.getScopeProvider().getResolutionScopeForDeclaration(declaration)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public class TopDownAnalyzer {
|
||||
|
||||
@Override
|
||||
public void visitAnonymousInitializer(@NotNull JetClassInitializer initializer) {
|
||||
registerScope(initializer, initializer);
|
||||
registerScope(initializer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,7 +272,7 @@ public class TopDownAnalyzer {
|
||||
(SimpleFunctionDescriptor) resolveSession.resolveToDescriptor(function)
|
||||
)
|
||||
);
|
||||
registerScope(function, function);
|
||||
registerScope(function);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,9 +284,9 @@ public class TopDownAnalyzer {
|
||||
c.getProperties().put(property, descriptor);
|
||||
registerTopLevelFqName(property, descriptor);
|
||||
|
||||
registerScope(property, property);
|
||||
registerScope(property.getGetter(), property);
|
||||
registerScope(property.getSetter(), property);
|
||||
registerScope(property);
|
||||
registerScope(property.getGetter());
|
||||
registerScope(property.getSetter());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -126,6 +126,11 @@ public class ScopeProvider {
|
||||
"For JetDeclaration element getParentOfType() should return itself.";
|
||||
|
||||
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(jetDeclaration, JetDeclaration.class);
|
||||
|
||||
if (jetDeclaration instanceof JetPropertyAccessor) {
|
||||
parentDeclaration = PsiTreeUtil.getParentOfType(parentDeclaration, JetDeclaration.class);
|
||||
}
|
||||
|
||||
if (parentDeclaration == null) {
|
||||
return getFileScope((JetFile) elementOfDeclaration.getContainingFile());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo(val a: Int, b: Int) {
|
||||
val c = a + b
|
||||
|
||||
val d: Int
|
||||
get() = a
|
||||
|
||||
val e: Int
|
||||
get() = <!UNRESOLVED_REFERENCE!>b<!>
|
||||
}
|
||||
@@ -364,6 +364,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/Properties.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyInitializers.kt")
|
||||
public void testPropertyInitializers() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/PropertyInitializers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("QualifiedExpressions.kt")
|
||||
public void testQualifiedExpressions() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt");
|
||||
|
||||
@@ -241,8 +241,8 @@ public class ResolveElementCache {
|
||||
descriptor.getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
|
||||
private static void propertyAdditionalResolve(ResolveSession resolveSession, final JetProperty jetProperty, BindingTrace trace, JetFile file) {
|
||||
final JetScope propertyResolutionScope = resolveSession.getScopeProvider().getResolutionScopeForDeclaration(jetProperty);
|
||||
private static void propertyAdditionalResolve(final ResolveSession resolveSession, final JetProperty jetProperty, BindingTrace trace, JetFile file) {
|
||||
JetScope propertyResolutionScope = resolveSession.getScopeProvider().getResolutionScopeForDeclaration(jetProperty);
|
||||
|
||||
BodyResolveContextForLazy bodyResolveContext = new BodyResolveContextForLazy(
|
||||
createParameters(resolveSession),
|
||||
@@ -251,7 +251,7 @@ public class ResolveElementCache {
|
||||
public JetScope apply(JetDeclaration declaration) {
|
||||
assert declaration.getParent() == jetProperty : "Must be called only for property accessors, but called for " +
|
||||
declaration;
|
||||
return propertyResolutionScope;
|
||||
return resolveSession.getScopeProvider().getResolutionScopeForDeclaration(declaration);
|
||||
}
|
||||
});
|
||||
BodyResolver bodyResolver = createBodyResolver(resolveSession, trace, file);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo(val a: Int, b: Int) {
|
||||
val e: Int
|
||||
get() = <caret>
|
||||
}
|
||||
|
||||
// EXIST: a
|
||||
// ABSENT: b
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo(val a: Int, b: Int) {
|
||||
val e: Int = <caret>
|
||||
}
|
||||
|
||||
// EXIST: a
|
||||
// EXIST: b
|
||||
@@ -294,6 +294,16 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
||||
doTest("idea/testData/completion/basic/common/InParametersTypesForce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InPropertyAccessor.kt")
|
||||
public void testInPropertyAccessor() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InPropertyAccessor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InPropertyInitializer.kt")
|
||||
public void testInPropertyInitializer() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InPropertyInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InTypeAnnotation.kt")
|
||||
public void testInTypeAnnotation() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InTypeAnnotation.kt");
|
||||
|
||||
@@ -294,6 +294,16 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
||||
doTest("idea/testData/completion/basic/common/InParametersTypesForce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InPropertyAccessor.kt")
|
||||
public void testInPropertyAccessor() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InPropertyAccessor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InPropertyInitializer.kt")
|
||||
public void testInPropertyInitializer() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InPropertyInitializer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InTypeAnnotation.kt")
|
||||
public void testInTypeAnnotation() throws Exception {
|
||||
doTest("idea/testData/completion/basic/common/InTypeAnnotation.kt");
|
||||
|
||||
Reference in New Issue
Block a user