Correct scope for property accessors in lazy resolve

This commit is contained in:
Andrey Breslav
2014-03-19 18:53:55 +04:00
parent 4dfb6763b2
commit 34c6eaec56
9 changed files with 62 additions and 10 deletions
@@ -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");