KT-20 Resolve class objects' contents in the 'static' scope
This commit is contained in:
@@ -37,7 +37,7 @@ public class TypeHierarchyResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(@NotNull JetScope outerScope, @NotNull NamespaceLike owner, @NotNull Collection<? extends JetDeclaration> declarations) {
|
public void process(@NotNull JetScope outerScope, @NotNull NamespaceLike owner, @NotNull Collection<? extends JetDeclaration> declarations) {
|
||||||
collectNamespacesAndClassifiers(outerScope, owner, declarations); // namespaceScopes, classes
|
collectNamespacesAndClassifiers(outerScope, outerScope, owner, declarations); // namespaceScopes, classes
|
||||||
|
|
||||||
processTypeImports();
|
processTypeImports();
|
||||||
|
|
||||||
@@ -62,6 +62,7 @@ public class TypeHierarchyResolver {
|
|||||||
|
|
||||||
private void collectNamespacesAndClassifiers(
|
private void collectNamespacesAndClassifiers(
|
||||||
@NotNull final JetScope outerScope,
|
@NotNull final JetScope outerScope,
|
||||||
|
@NotNull final JetScope outerScopeForStatic,
|
||||||
@NotNull final NamespaceLike owner,
|
@NotNull final NamespaceLike owner,
|
||||||
@NotNull Collection<? extends JetDeclaration> declarations) {
|
@NotNull Collection<? extends JetDeclaration> declarations) {
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
@@ -89,7 +90,7 @@ public class TypeHierarchyResolver {
|
|||||||
|
|
||||||
// processImports(namespace, namespaceScope, outerScope);
|
// processImports(namespace, namespaceScope, outerScope);
|
||||||
|
|
||||||
collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
|
collectNamespacesAndClassifiers(namespaceScope, namespaceScope, namespaceDescriptor, namespace.getDeclarations());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -116,7 +117,7 @@ public class TypeHierarchyResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||||
createClassDescriptorForObject(declaration, owner);
|
createClassDescriptorForObject(declaration, owner, outerScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +125,7 @@ public class TypeHierarchyResolver {
|
|||||||
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor();
|
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor();
|
||||||
assert classObjectDescriptor != null : enumEntry.getParent().getText();
|
assert classObjectDescriptor != null : enumEntry.getParent().getText();
|
||||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||||
MutableClassDescriptor classDescriptor = createClassDescriptorForObject(enumEntry, classObjectDescriptor);
|
MutableClassDescriptor classDescriptor = createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic);
|
||||||
context.getObjects().remove(enumEntry);
|
context.getObjects().remove(enumEntry);
|
||||||
context.getClasses().put(enumEntry, classDescriptor);
|
context.getClasses().put(enumEntry, classDescriptor);
|
||||||
}
|
}
|
||||||
@@ -140,14 +141,14 @@ public class TypeHierarchyResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner) {
|
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner, JetScope scope) {
|
||||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, ClassKind.OBJECT) {
|
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, ClassKind.OBJECT) {
|
||||||
@Override
|
@Override
|
||||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||||
return ClassObjectStatus.NOT_ALLOWED;
|
return ClassObjectStatus.NOT_ALLOWED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
visitClassOrObject(declaration, (Map) context.getObjects(), owner, outerScope, mutableClassDescriptor);
|
visitClassOrObject(declaration, (Map) context.getObjects(), owner, scope, mutableClassDescriptor);
|
||||||
createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
|
createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
|
||||||
context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
|
context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
|
||||||
return mutableClassDescriptor;
|
return mutableClassDescriptor;
|
||||||
@@ -171,7 +172,7 @@ public class TypeHierarchyResolver {
|
|||||||
// declaringScopes.put((JetDeclaration) declaration, outerScope);
|
// declaringScopes.put((JetDeclaration) declaration, outerScope);
|
||||||
|
|
||||||
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
|
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
|
||||||
collectNamespacesAndClassifiers(classScope, mutableClassDescriptor, declaration.getDeclarations());
|
collectNamespacesAndClassifiers(classScope, outerScopeForStatic, mutableClassDescriptor, declaration.getDeclarations());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,7 +185,7 @@ public class TypeHierarchyResolver {
|
|||||||
public void visitClassObject(JetClassObject classObject) {
|
public void visitClassObject(JetClassObject classObject) {
|
||||||
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
|
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
|
||||||
if (objectDeclaration != null) {
|
if (objectDeclaration != null) {
|
||||||
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner));
|
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic));
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DUPLICATE:
|
case DUPLICATE:
|
||||||
// context.getTrace().getErrorHandler().genericError(classObject.getNode(), "Only one class object is allowed per class");
|
// context.getTrace().getErrorHandler().genericError(classObject.getNode(), "Only one class object is allowed per class");
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// http://youtrack.jetbrains.net/issue/KT-20
|
||||||
|
|
||||||
|
class A() {
|
||||||
|
val x = 1
|
||||||
|
|
||||||
|
class object {
|
||||||
|
val y = <!UNRESOLVED_REFERENCE!>x<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user