Object constructors fixed
This commit is contained in:
@@ -128,7 +128,7 @@ public class DeclarationResolver {
|
||||
}
|
||||
|
||||
private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) {
|
||||
if (!klass.hasPrimaryConstructor() && classDescriptor.getKind() != ClassKind.OBJECT) return;
|
||||
if (!klass.hasPrimaryConstructor()) return;
|
||||
|
||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||
// context.getTrace().getErrorHandler().genericError(klass.getPrimaryConstructorParameterList().getNode(), "A trait may not have a constructor");
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -20,6 +21,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DESCRIPTOR_TO_DECLARATION;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE;
|
||||
|
||||
@@ -98,7 +100,7 @@ public class TypeHierarchyResolver {
|
||||
classObjectDescriptor.setModality(Modality.FINAL);
|
||||
classObjectDescriptor.setVisibility(ClassDescriptorResolver.resolveVisibilityFromModifiers(context.getTrace(), klass.getModifierList()));
|
||||
classObjectDescriptor.createTypeConstructor();
|
||||
createPrimaryConstructor(classObjectDescriptor);
|
||||
createPrimaryConstructorForObject(null, classObjectDescriptor);
|
||||
mutableClassDescriptor.setClassObjectDescriptor(classObjectDescriptor);
|
||||
}
|
||||
visitClassOrObject(
|
||||
@@ -144,17 +146,20 @@ public class TypeHierarchyResolver {
|
||||
}
|
||||
};
|
||||
visitClassOrObject(declaration, (Map) context.getObjects(), owner, outerScope, mutableClassDescriptor);
|
||||
createPrimaryConstructor(mutableClassDescriptor);
|
||||
createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
|
||||
context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
|
||||
return mutableClassDescriptor;
|
||||
}
|
||||
|
||||
private void createPrimaryConstructor(MutableClassDescriptor mutableClassDescriptor) {
|
||||
private void createPrimaryConstructorForObject(@Nullable JetDeclaration object, MutableClassDescriptor mutableClassDescriptor) {
|
||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||
Modality.FINAL, Visibility.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
|
||||
// TODO : make the constructor private?
|
||||
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor);
|
||||
if (object != null) {
|
||||
context.getTrace().record(CONSTRUCTOR, object, constructorDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private void visitClassOrObject(@NotNull JetClassOrObject declaration, Map<JetClassOrObject, MutableClassDescriptor> map, NamespaceLike owner, JetScope outerScope, MutableClassDescriptor mutableClassDescriptor) {
|
||||
|
||||
@@ -875,30 +875,27 @@ public class JetTypeInferrer {
|
||||
@Override
|
||||
public JetType visitObjectLiteralExpression(final JetObjectLiteralExpression expression, final TypeInferenceContext context) {
|
||||
final JetType[] result = new JetType[1];
|
||||
BindingTraceAdapter.RecordHandler<PsiElement, DeclarationDescriptor> handler = new BindingTraceAdapter.RecordHandler<PsiElement, DeclarationDescriptor>() {
|
||||
BindingTraceAdapter.RecordHandler<PsiElement, ClassDescriptor> handler = new BindingTraceAdapter.RecordHandler<PsiElement, ClassDescriptor>() {
|
||||
|
||||
@Override
|
||||
public void handleRecord(WritableSlice<PsiElement, DeclarationDescriptor> slice, PsiElement declaration, final DeclarationDescriptor descriptor) {
|
||||
if (declaration == expression.getObjectDeclaration()) {
|
||||
public void handleRecord(WritableSlice<PsiElement, ClassDescriptor> slice, PsiElement declaration, final ClassDescriptor descriptor) {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
JetType defaultType = new DeferredType(new LazyValue<JetType>() {
|
||||
@Override
|
||||
protected JetType compute() {
|
||||
return ((ClassDescriptor) descriptor).getDefaultType();
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
});
|
||||
result[0] = defaultType;
|
||||
if (!context.trace.get(BindingContext.PROCESSED, expression)) {
|
||||
context.trace.record(BindingContext.EXPRESSION_TYPE, expression, defaultType);
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
if (!context.trace.get(PROCESSED, expression)) {
|
||||
context.trace.record(EXPRESSION_TYPE, expression, defaultType);
|
||||
context.trace.record(PROCESSED, expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
BindingTraceAdapter traceAdapter = new BindingTraceAdapter(context.trace);
|
||||
for (WritableSlice slice : BindingContext.DECLARATIONS_TO_DESCRIPTORS) {
|
||||
//noinspection unchecked
|
||||
traceAdapter.addHandler(slice, handler);
|
||||
}
|
||||
traceAdapter.addHandler(CLASS, handler);
|
||||
TopDownAnalyzer.processObject(semanticServices, traceAdapter, context.scope, context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
|
||||
return context.services.checkType(result[0], expression, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user