All tests pass

This commit is contained in:
Andrey Breslav
2011-05-16 20:48:51 +04:00
parent f61b776c10
commit 0f63489f7c
5 changed files with 219 additions and 198 deletions
@@ -19,17 +19,19 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>"); private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
private final Set<FunctionDescriptor> functions = Sets.newHashSet(); private final Set<FunctionDescriptor> functions = Sets.newHashSet();
private final Set<PropertyDescriptor> properties = Sets.newHashSet(); private final Set<PropertyDescriptor> properties = Sets.newHashSet();
private final Set<MutableClassDescriptor> classes = Sets.newHashSet();
private TypeConstructor typeConstructor; private TypeConstructor typeConstructor;
private final WritableScope scopeForMemberResolution; private final WritableScope scopeForMemberResolution;
private final WritableScope scopeForMemberLookup; private final WritableScope scopeForMemberLookup;
// This scope contains type parameters but does not contain inner classes
private final WritableScope scopeForSupertypeResolution;
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) { public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
super(containingDeclaration); super(containingDeclaration);
this.scopeForMemberResolution = new WritableScopeImpl(outerScope, this, trace.getErrorHandler(), null); this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace.getErrorHandler(), null);
this.scopeForMemberLookup = new WritableScopeImpl(scopeForMemberResolution, this, trace.getErrorHandler(), null); this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace.getErrorHandler(), null);
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, trace.getErrorHandler(), null);
// this.scopeForMemberLookup = new WritableScopeImpl(scopeForMemberResolution, this, trace.getErrorHandler(), new DeclarationDescriptorVisitor<Void, WritableScope>() { // this.scopeForMemberLookup = new WritableScopeImpl(scopeForMemberResolution, this, trace.getErrorHandler(), new DeclarationDescriptorVisitor<Void, WritableScope>() {
// @Override // @Override
// public Void visitPropertyDescriptor(PropertyDescriptor descriptor, WritableScope data) { // public Void visitPropertyDescriptor(PropertyDescriptor descriptor, WritableScope data) {
@@ -100,7 +102,6 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
@Override @Override
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) { public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
classes.add(classDescriptor);
scopeForMemberLookup.addClassifierDescriptor(classDescriptor); scopeForMemberLookup.addClassifierDescriptor(classDescriptor);
scopeForMemberResolution.addClassifierDescriptor(classDescriptor); scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
} }
@@ -178,4 +179,14 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
public String toString() { public String toString() {
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]"; return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
} }
public void addSupertype(@NotNull JetType supertype) {
scopeForMemberLookup.importScope(supertype.getMemberScope());
scopeForMemberResolution.importScope(supertype.getMemberScope());
}
@NotNull
public WritableScope getScopeForSupertypeResolution() {
return scopeForSupertypeResolution;
}
} }
@@ -81,7 +81,7 @@ public class ClassDescriptorResolver {
descriptor.setName(JetPsiUtil.safeName(classElement.getName())); descriptor.setName(JetPsiUtil.safeName(classElement.getName()));
descriptor.getScopeForMemberResolution().addLabeledDeclaration(descriptor); descriptor.getScopeForMemberResolution().addLabeledDeclaration(descriptor);
WritableScope scopeForMemberResolution = descriptor.getScopeForMemberResolution(); WritableScope scopeForMemberResolution = descriptor.getScopeForSupertypeResolution();
// TODO : Where-clause // TODO : Where-clause
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList(); List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
@@ -126,7 +126,7 @@ public class ClassDescriptorResolver {
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i); TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound(); JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
if (extendsBound != null) { if (extendsBound != null) {
typeParameterDescriptor.addUpperBound(typeResolverNotCheckingBounds.resolveType(classDescriptor.getScopeForMemberResolution(), extendsBound)); typeParameterDescriptor.addUpperBound(typeResolverNotCheckingBounds.resolveType(classDescriptor.getScopeForSupertypeResolution(), extendsBound));
} }
else { else {
typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound()); typeParameterDescriptor.addUpperBound(JetStandardClasses.getDefaultBound());
@@ -140,13 +140,12 @@ public class ClassDescriptorResolver {
// TODO : assuming that the hierarchy is acyclic // TODO : assuming that the hierarchy is acyclic
Collection<? extends JetType> superclasses = delegationSpecifiers.isEmpty() Collection<? extends JetType> superclasses = delegationSpecifiers.isEmpty()
? Collections.singleton(JetStandardClasses.getAnyType()) ? Collections.singleton(JetStandardClasses.getAnyType())
: resolveDelegationSpecifiers(descriptor.getScopeForMemberResolution(), delegationSpecifiers, typeResolverNotCheckingBounds); : resolveDelegationSpecifiers(descriptor.getScopeForSupertypeResolution(), delegationSpecifiers, typeResolverNotCheckingBounds);
((TypeConstructorImpl) descriptor.getTypeConstructor()).getSupertypes().addAll(superclasses); ((TypeConstructorImpl) descriptor.getTypeConstructor()).getSupertypes().addAll(superclasses);
// TODO : remove the importing // TODO : remove the importing
for (JetType superclass : superclasses) { for (JetType superclass : superclasses) {
descriptor.getScopeForMemberResolution().importScope(superclass.getMemberScope()); descriptor.addSupertype(superclass);
} }
} }
@@ -154,7 +153,7 @@ public class ClassDescriptorResolver {
descriptor.setName(JetPsiUtil.safeName(classElement.getName())); descriptor.setName(JetPsiUtil.safeName(classElement.getName()));
descriptor.getScopeForMemberResolution().addLabeledDeclaration(descriptor); descriptor.getScopeForMemberResolution().addLabeledDeclaration(descriptor);
WritableScope parameterScope = descriptor.getScopeForMemberResolution(); WritableScope parameterScope = descriptor.getScopeForSupertypeResolution();
// This call has side-effects on the parameterScope (fills it in) // This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters List<TypeParameterDescriptor> typeParameters
@@ -266,174 +266,174 @@ public class TopDownAnalyzer {
resolveBehaviorDeclarationBodies(); resolveBehaviorDeclarationBodies();
} }
@NotNull // @NotNull
public JetScope process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) { // public JetScope process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) {
final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?! // final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?!
//
collectTypeDeclarators(toplevelScope, declarations); // collectTypeDeclarators(toplevelScope, declarations);
resolveTypeDeclarations(); // resolveTypeDeclarations();
processBehaviorDeclarators(toplevelScope, declarations); // processBehaviorDeclarators(toplevelScope, declarations);
readyToProcessExpressions = true; // readyToProcessExpressions = true;
resolveBehaviorDeclarationBodies(); // resolveBehaviorDeclarationBodies();
return toplevelScope; // return toplevelScope;
} // }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void collectTypeDeclarators( // private void collectTypeDeclarators(
@NotNull final WritableScope declaringScope, // @NotNull final WritableScope declaringScope,
List<JetDeclaration> declarations) { // List<JetDeclaration> declarations) {
for (JetDeclaration declaration : declarations) { // for (JetDeclaration declaration : declarations) {
declaration.accept(new JetVisitor() { // declaration.accept(new JetVisitor() {
@Override // @Override
public void visitNamespace(JetNamespace namespace) { // public void visitNamespace(JetNamespace namespace) {
List<JetImportDirective> importDirectives = namespace.getImportDirectives(); // List<JetImportDirective> importDirectives = namespace.getImportDirectives();
//
String name = namespace.getName(); // String name = namespace.getName();
if (name == null) { // if (name == null) {
name = "<no name provided>"; // name = "<no name provided>";
} // }
NamespaceDescriptorImpl namespaceDescriptor = (NamespaceDescriptorImpl) declaringScope.getDeclaredNamespace(name); // NamespaceDescriptorImpl namespaceDescriptor = (NamespaceDescriptorImpl) declaringScope.getDeclaredNamespace(name);
if (namespaceDescriptor == null) { // if (namespaceDescriptor == null) {
namespaceDescriptor = new NamespaceDescriptorImpl( // namespaceDescriptor = new NamespaceDescriptorImpl(
declaringScope.getContainingDeclaration(), // declaringScope.getContainingDeclaration(),
Collections.<Annotation>emptyList(), // TODO // Collections.<Annotation>emptyList(), // TODO
name // name
); // );
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler(), null)); // namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler(), null));
declaringScope.addNamespace(namespaceDescriptor); // declaringScope.addNamespace(namespaceDescriptor);
trace.recordDeclarationResolution(namespace, namespaceDescriptor); // trace.recordDeclarationResolution(namespace, namespaceDescriptor);
} // }
//
WritableScope namespaceScope = new WriteThroughScope(declaringScope, (WritableScope) namespaceDescriptor.getMemberScope()); // WritableScope namespaceScope = new WriteThroughScope(declaringScope, (WritableScope) namespaceDescriptor.getMemberScope());
namespaceScopes.put(namespace, namespaceScope); // namespaceScopes.put(namespace, namespaceScope);
//
for (JetImportDirective importDirective : importDirectives) { // for (JetImportDirective importDirective : importDirectives) {
if (importDirective.isAbsoluteInRootNamespace()) { // if (importDirective.isAbsoluteInRootNamespace()) {
throw new UnsupportedOperationException(); // throw new UnsupportedOperationException();
} // }
if (importDirective.isAllUnder()) { // if (importDirective.isAllUnder()) {
JetExpression importedReference = importDirective.getImportedReference(); // JetExpression importedReference = importDirective.getImportedReference();
if (importedReference != null) { // if (importedReference != null) {
JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false); // JetType type = semanticServices.getTypeInferrer(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false);
if (type != null) { // if (type != null) {
namespaceScope.importScope(type.getMemberScope()); // namespaceScope.importScope(type.getMemberScope());
} // }
} // }
} else { // } else {
throw new UnsupportedOperationException(); // throw new UnsupportedOperationException();
} // }
} // }
//
collectTypeDeclarators(namespaceScope, namespace.getDeclarations()); // collectTypeDeclarators(namespaceScope, namespace.getDeclarations());
} // }
//
@Override // @Override
public void visitClass(JetClass klass) { // public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope); // MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope);
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName())); // mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
//
declaringScope.addClassifierDescriptor(mutableClassDescriptor); // declaringScope.addClassifierDescriptor(mutableClassDescriptor);
//
classes.put(klass, mutableClassDescriptor); // classes.put(klass, mutableClassDescriptor);
declaringScopes.put(klass, declaringScope); // declaringScopes.put(klass, declaringScope);
//
WritableScope classScope = mutableClassDescriptor.getScopeForMemberLookup(); // WritableScope classScope = mutableClassDescriptor.getScopeForMemberLookup();
collectTypeDeclarators(classScope, klass.getDeclarations()); // collectTypeDeclarators(classScope, klass.getDeclarations());
} // }
//
@Override // @Override
public void visitTypedef(JetTypedef typedef) { // public void visitTypedef(JetTypedef typedef) {
trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]"); // trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]");
} // }
//
@Override // @Override
public void visitExtension(JetExtension extension) { // public void visitExtension(JetExtension extension) {
trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]"); // trace.getErrorHandler().genericError(extension.getNode(), "Unsupported [TopDownAnalyzer]");
} // }
//
@Override // @Override
public void visitDeclaration(JetDeclaration dcl) { // public void visitDeclaration(JetDeclaration dcl) {
// Other declarations do not declare visible types // // Other declarations do not declare visible types
} // }
}); // });
} // }
} // }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void resolveTypeDeclarations() { // private void resolveTypeDeclarations() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) { // for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
JetClass jetClass = entry.getKey(); // JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); // MutableClassDescriptor descriptor = entry.getValue();
classDescriptorResolver.resolveMutableClassDescriptor(declaringScopes.get(jetClass), jetClass, descriptor); // classDescriptorResolver.resolveMutableClassDescriptor(declaringScopes.get(jetClass), jetClass, descriptor);
} // }
} // }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void processBehaviorDeclarators(@NotNull final WritableScope declaringScope, List<JetDeclaration> declarations) { // private void processBehaviorDeclarators(@NotNull final WritableScope declaringScope, List<JetDeclaration> declarations) {
for (JetDeclaration declaration : declarations) { // for (JetDeclaration declaration : declarations) {
declaration.accept(new JetVisitor() { // declaration.accept(new JetVisitor() {
@Override // @Override
public void visitClass(JetClass klass) { // public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = classes.get(klass); // MutableClassDescriptor mutableClassDescriptor = classes.get(klass);
processPrimaryConstructor(mutableClassDescriptor, klass); // processPrimaryConstructor(mutableClassDescriptor, klass);
processBehaviorDeclarators(mutableClassDescriptor.getScopeForMemberLookup(), klass.getDeclarations()); // processBehaviorDeclarators(mutableClassDescriptor.getScopeForMemberLookup(), klass.getDeclarations());
} // }
//
@Override // @Override
public void visitClassObject(JetClassObject classObject) { // public void visitClassObject(JetClassObject classObject) {
processClassObject(classObject); // processClassObject(classObject);
processBehaviorDeclarators(declaringScope, classObject.getObject().getDeclarations()); // processBehaviorDeclarators(declaringScope, classObject.getObject().getDeclarations());
} // }
//
@Override // @Override
public void visitNamespace(JetNamespace namespace) { // public void visitNamespace(JetNamespace namespace) {
WritableScope namespaceScope = namespaceScopes.get(namespace); // WritableScope namespaceScope = namespaceScopes.get(namespace);
processBehaviorDeclarators(namespaceScope, namespace.getDeclarations()); // processBehaviorDeclarators(namespaceScope, namespace.getDeclarations());
} // }
//
@Override // @Override
public void visitFunction(JetFunction function) { // public void visitFunction(JetFunction function) {
processFunction(declaringScope, function); // processFunction(declaringScope, function);
} // }
//
@Override // @Override
public void visitProperty(JetProperty property) { // public void visitProperty(JetProperty property) {
processProperty(declaringScope, property); // processProperty(declaringScope, property);
} // }
//
@Override // @Override
public void visitConstructor(JetConstructor constructor) { // public void visitConstructor(JetConstructor constructor) {
DeclarationDescriptor containingDeclaration = declaringScope.getContainingDeclaration(); // DeclarationDescriptor containingDeclaration = declaringScope.getContainingDeclaration();
if (containingDeclaration instanceof ClassDescriptor) { // if (containingDeclaration instanceof ClassDescriptor) {
processSecondaryConstructor((MutableClassDescriptor) containingDeclaration, constructor); // processSecondaryConstructor((MutableClassDescriptor) containingDeclaration, constructor);
} // }
else { // else {
trace.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes"); // trace.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes");
} // }
} // }
//
@Override // @Override
public void visitAnonymousInitializer(JetClassInitializer initializer) { // public void visitAnonymousInitializer(JetClassInitializer initializer) {
// Nothing // // Nothing
} // }
//
@Override // @Override
public void visitDeclaration(JetDeclaration dcl) { // public void visitDeclaration(JetDeclaration dcl) {
trace.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO // trace.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO
} // }
}); // });
} // }
//
} // }
private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) { private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) {
if (!klass.hasPrimaryConstructor()) return; if (!klass.hasPrimaryConstructor()) return;
// TODO : not all the parameters are real properties // TODO : not all the parameters are real properties
WritableScope memberScope = classDescriptor.getScopeForMemberLookup(); // TODO : this is REALLY questionable WritableScope memberScope = classDescriptor.getScopeForMemberResolution(); // TODO : this is REALLY questionable
ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass); ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) { for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePrimaryConstructorParameterToAProperty( PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePrimaryConstructorParameterToAProperty(
@@ -441,8 +441,7 @@ public class TopDownAnalyzer {
memberScope, memberScope,
parameter parameter
); );
memberScope.addVariableDescriptor( classDescriptor.addPropertyDescriptor(propertyDescriptor);
propertyDescriptor);
primaryConstructorParameterProperties.add(propertyDescriptor); primaryConstructorParameterProperties.add(propertyDescriptor);
} }
if (constructorDescriptor != null) { if (constructorDescriptor != null) {
@@ -452,7 +451,7 @@ public class TopDownAnalyzer {
private void processSecondaryConstructor(MutableClassDescriptor classDescriptor, JetConstructor constructor) { private void processSecondaryConstructor(MutableClassDescriptor classDescriptor, JetConstructor constructor) {
ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor( ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor(
classDescriptor.getScopeForMemberLookup(), classDescriptor.getScopeForMemberResolution(),
classDescriptor, classDescriptor,
constructor); constructor);
classDescriptor.addConstructor(constructorDescriptor); classDescriptor.addConstructor(constructorDescriptor);
@@ -460,25 +459,25 @@ public class TopDownAnalyzer {
declaringScopes.put(constructor, classDescriptor.getScopeForMemberLookup()); declaringScopes.put(constructor, classDescriptor.getScopeForMemberLookup());
} }
private void processFunction(@NotNull WritableScope declaringScope, JetFunction function) { // private void processFunction(@NotNull WritableScope declaringScope, JetFunction function) {
declaringScopes.put(function, declaringScope); // declaringScopes.put(function, declaringScope);
FunctionDescriptorImpl descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope.getContainingDeclaration(), declaringScope, function); // FunctionDescriptorImpl descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope.getContainingDeclaration(), declaringScope, function);
declaringScope.addFunctionDescriptor(descriptor); // declaringScope.addFunctionDescriptor(descriptor);
functions.put(function, descriptor); // functions.put(function, descriptor);
} // }
//
private void processProperty(WritableScope declaringScope, JetProperty property) { // private void processProperty(WritableScope declaringScope, JetProperty property) {
declaringScopes.put(property, declaringScope); // declaringScopes.put(property, declaringScope);
// TODO : Do not infer the type from the initializer here: the scope is wrong, and not ready anyway // // TODO : Do not infer the type from the initializer here: the scope is wrong, and not ready anyway
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property); // PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property);
declaringScope.addVariableDescriptor(descriptor); // declaringScope.addVariableDescriptor(descriptor);
declaringScopesToProperties.put(declaringScope.getContainingDeclaration(), descriptor); // declaringScopesToProperties.put(declaringScope.getContainingDeclaration(), descriptor);
properties.put(property, descriptor); // properties.put(property, descriptor);
} // }
//
private void processClassObject(JetClassObject classObject) { // private void processClassObject(JetClassObject classObject) {
trace.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO // trace.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO
} // }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -550,7 +549,9 @@ public class TopDownAnalyzer {
final JetClass jetClass = entry.getKey(); final JetClass jetClass = entry.getKey();
final MutableClassDescriptor descriptor = entry.getValue(); final MutableClassDescriptor descriptor = entry.getValue();
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor(); final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
final JetScope scopeForConstructor = primaryConstructor == null ? null : getInnerScopeForConstructor(primaryConstructor, descriptor.getScopeForMemberLookup()); final JetScope scopeForConstructor = primaryConstructor == null
? null
: getInnerScopeForConstructor(primaryConstructor, descriptor.getScopeForMemberResolution());
final JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow final JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) { for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
@@ -559,7 +560,7 @@ public class TopDownAnalyzer {
public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) { public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) {
JetExpression delegateExpression = specifier.getDelegateExpression(); JetExpression delegateExpression = specifier.getDelegateExpression();
if (delegateExpression != null) { if (delegateExpression != null) {
JetScope scope = scopeForConstructor == null ? descriptor.getScopeForMemberLookup() : scopeForConstructor; JetScope scope = scopeForConstructor == null ? descriptor.getScopeForMemberResolution() : scopeForConstructor;
JetType type = typeInferrer.getType(scope, delegateExpression, false); JetType type = typeInferrer.getType(scope, delegateExpression, false);
JetType supertype = trace.resolveTypeReference(specifier.getTypeReference()); JetType supertype = trace.resolveTypeReference(specifier.getTypeReference());
if (type != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { // TODO : Convertible? if (type != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { // TODO : Convertible?
@@ -625,7 +626,7 @@ public class TopDownAnalyzer {
if (jetClass.hasPrimaryConstructor()) { if (jetClass.hasPrimaryConstructor()) {
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor(); ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
assert primaryConstructor != null; assert primaryConstructor != null;
final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberLookup()); final JetScope scopeForConstructor = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution());
JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow JetTypeInferrer typeInferrer = semanticServices.getTypeInferrer(traceForConstructors, JetFlowInformationProvider.NONE); // TODO : flow
for (JetClassInitializer anonymousInitializer : anonymousInitializers) { for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), true); typeInferrer.getType(scopeForConstructor, anonymousInitializer.getBody(), true);
@@ -725,7 +726,7 @@ public class TopDownAnalyzer {
@NotNull @NotNull
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope) { private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope) {
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null); WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null);
for (PropertyDescriptor propertyDescriptor : declaringScopesToProperties.get(descriptor.getContainingDeclaration())) { for (PropertyDescriptor propertyDescriptor : ((MutableClassDescriptor) descriptor.getContainingDeclaration()).getProperties()) {
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor); constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
} }
return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, trace); return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, trace);
@@ -752,7 +753,7 @@ public class TopDownAnalyzer {
trace.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present"); trace.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
} }
else { else {
JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberLookup()); JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getScopeForMemberResolution());
resolvePropertyInitializer(property, propertyDescriptor, initializer, scope); resolvePropertyInitializer(property, propertyDescriptor, initializer, scope);
} }
} }
@@ -183,13 +183,14 @@ public class WritableScopeImpl extends WritableScopeWithImports {
@Override @Override
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) { public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
String name = typeParameterDescriptor.getName(); String name = typeParameterDescriptor.getName();
Map<String, ClassifierDescriptor> classifierDescriptors = getClassifierDescriptors(); addClassifierAlias(name, typeParameterDescriptor);
ClassifierDescriptor originalDescriptor = classifierDescriptors.get(name); // Map<String, ClassifierDescriptor> classifierDescriptors = getClassifierDescriptors();
if (originalDescriptor != null) { // ClassifierDescriptor originalDescriptor = classifierDescriptors.get(name);
errorHandler.redeclaration(originalDescriptor, typeParameterDescriptor); // if (originalDescriptor != null) {
} // errorHandler.redeclaration(originalDescriptor, typeParameterDescriptor);
classifierDescriptors.put(name, typeParameterDescriptor); // }
notifyListeners(typeParameterDescriptor); // classifierDescriptors.put(name, typeParameterDescriptor);
// notifyListeners(typeParameterDescriptor);
} }
@NotNull @NotNull
@@ -0,0 +1,9 @@
var xxxx = 1
~SimpleClass~class SimpleClass(x : Int) {
fun foo() = x
}
fun foo() {
new `SimpleClass`SimpleClass(1).`!`xxxx
}