From ac06825f0870ed7ddb02552d3599f52a16bb4fb6 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 26 Jun 2012 18:52:32 +0200 Subject: [PATCH] jet.Any: modality and constructor straightened --- .../jet/codegen/ClosureAnnotator.java | 6 +- .../lang/descriptors/ClassDescriptorImpl.java | 5 +- .../jetbrains/jet/lang/types/ErrorUtils.java | 2 +- .../lang/types/lang/JetStandardClasses.java | 60 ++++++++++++------- .../testData/codegen/regressions/kt1249.kt | 2 +- .../jet/types/JetTypeCheckerTest.java | 1 + 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java index 94e13393852..74fe392840e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureAnnotator.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.codegen; -import com.intellij.openapi.util.Pair; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,14 +24,13 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.DescriptorUtils; -import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmClassName; +import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.*; @@ -78,6 +76,7 @@ public class ClosureAnnotator { classDescriptor = new ClassDescriptorImpl( funDescriptor, Collections.emptyList(), + Modality.FINAL, Name.special("")); recordName(classDescriptor, name); classDescriptor.initialize( @@ -102,6 +101,7 @@ public class ClosureAnnotator { ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl( scriptDescriptor, Collections.emptyList(), + Modality.FINAL, Name.special("")); recordName(classDescriptor, className); classDescriptor.initialize( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java index 837d71f6bc7..c4e04e927c0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java @@ -39,12 +39,15 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem private Set constructors; private ConstructorDescriptor primaryConstructor; private ReceiverDescriptor implicitReceiver; + private final Modality modality; public ClassDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, @NotNull List annotations, + @NotNull Modality modality, @NotNull Name name) { super(containingDeclaration, annotations, name); + this.modality = modality; } public final ClassDescriptorImpl initialize(boolean sealed, @@ -155,7 +158,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem @Override @NotNull public Modality getModality() { - return Modality.FINAL; + return modality; } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java index 27703d7c531..f07c259b58b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/ErrorUtils.java @@ -118,7 +118,7 @@ public class ErrorUtils { } - private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.emptyList(), Name.special("")) { + private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.emptyList(), Modality.OPEN, Name.special("")) { @NotNull @Override public Collection getConstructors() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java index 77465b26b64..af503d4138b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java @@ -70,6 +70,7 @@ public class JetStandardClasses { private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl( STANDARD_CLASSES_NAMESPACE, Collections.emptyList(), + Modality.FINAL, Name.identifier("Nothing") ).initialize( true, @@ -106,31 +107,41 @@ public class JetStandardClasses { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - private static final ClassDescriptor ANY = new ClassDescriptorImpl( - STANDARD_CLASSES_NAMESPACE, - Collections.emptyList(), - Name.identifier("Any")).initialize( - false, - Collections.emptyList(), - Collections.emptySet(), - JetScope.EMPTY, - Collections.emptySet(), - null, - null - ); + private static final ClassDescriptor ANY; + private static final JetType ANY_TYPE; - private static final JetType ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), new JetScopeImpl() { - @NotNull - @Override - public DeclarationDescriptor getContainingDeclaration() { - return STANDARD_CLASSES_NAMESPACE; - } + static { + ClassDescriptorImpl any = new ClassDescriptorImpl( + STANDARD_CLASSES_NAMESPACE, + Collections.emptyList(), + Modality.OPEN, + Name.identifier("Any") + ); + ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(any, Collections.emptyList(), true); + constructorDescriptor.initialize(Collections.emptyList(), Collections.emptyList(), Visibilities.PUBLIC); + ANY = any.initialize( + false, + Collections.emptyList(), + Collections.emptySet(), + JetScope.EMPTY, + Collections.singleton(constructorDescriptor), + null, + null + ); + ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), new JetScopeImpl() { + @NotNull + @Override + public DeclarationDescriptor getContainingDeclaration() { + return STANDARD_CLASSES_NAMESPACE; + } - @Override - public String toString() { - return "Scope for Any"; - } - }); + @Override + public String toString() { + return "Scope for Any"; + } + }); + constructorDescriptor.setReturnType(ANY_TYPE); + } private static final JetType NULLABLE_ANY_TYPE = new JetTypeImpl(ANY_TYPE.getAnnotations(), ANY_TYPE.getConstructor(), true, ANY_TYPE.getArguments(), ANY_TYPE.getMemberScope()); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -154,6 +165,7 @@ public class JetStandardClasses { ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl( STANDARD_CLASSES_NAMESPACE, Collections.emptyList(), + Modality.FINAL, Name.identifier("Tuple" + i)); WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION, "tuples"); for (int j = 0; j < i; j++) { @@ -196,6 +208,7 @@ public class JetStandardClasses { ClassDescriptorImpl function = new ClassDescriptorImpl( STANDARD_CLASSES_NAMESPACE, Collections.emptyList(), + Modality.OPEN, Name.identifier("Function" + i)); SimpleFunctionDescriptorImpl invoke = new SimpleFunctionDescriptorImpl(function, Collections.emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION); @@ -211,6 +224,7 @@ public class JetStandardClasses { ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl( STANDARD_CLASSES_NAMESPACE, Collections.emptyList(), + Modality.OPEN, Name.identifier("ExtensionFunction" + i)); SimpleFunctionDescriptorImpl invokeWithReceiver = new SimpleFunctionDescriptorImpl(receiverFunction, Collections.emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION); WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver); diff --git a/compiler/testData/codegen/regressions/kt1249.kt b/compiler/testData/codegen/regressions/kt1249.kt index 13d136fe06d..8078f5443fe 100644 --- a/compiler/testData/codegen/regressions/kt1249.kt +++ b/compiler/testData/codegen/regressions/kt1249.kt @@ -1,5 +1,5 @@ //KT-1249 IllegalStateException invoking function property -class TestClass(val body : () -> Unit) : Any { +class TestClass(val body : () -> Unit) : Any() { fun run() { body() } diff --git a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index dc376d30df3..c0cf7c46ba8 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -689,6 +689,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { final ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl( scope.getContainingDeclaration(), Collections.emptyList(), + Modality.FINAL, JetPsiUtil.safeName(classElement.getName())); BindingTrace trace = JetTestUtils.DUMMY_TRACE;