KT-650 Prohibit creating class without constructor

This commit is contained in:
svtk
2012-01-24 15:41:38 +04:00
parent ee5fcccda9
commit 70d0cd882b
43 changed files with 170 additions and 218 deletions
@@ -7,6 +7,7 @@ public enum ClassKind {
CLASS,
TRAIT,
ENUM_CLASS,
ENUM_ENTRY,
ANNOTATION_CLASS,
OBJECT
}
@@ -116,7 +116,6 @@ public interface Errors {
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
DiagnosticWithParameterFactory<JetProperty, JetClass> PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present", DiagnosticParameters.CLASS);
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
@NotNull
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) {
@@ -141,19 +140,13 @@ public interface Errors {
SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimpleDiagnosticFactory.create(ERROR, "Constructor invocation should be explicitly specified");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = SimpleDiagnosticFactory.create(ERROR, "A secondary constructor may appear only in a class that has a primary constructor");
SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST = SimpleDiagnosticFactory.create(ERROR, "Secondary constructors must have an initializer list");
SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required");
SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
PsiElementOnlyDiagnosticFactory1<JetModifierList, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory1<JetClass, PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field");
ParameterizedDiagnosticFactory1<JetClassOrObject> PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1<JetClassOrObject>(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") {
@Override
protected String makeMessageFor(@NotNull JetClassOrObject argument) {
return JetPsiUtil.safeName(argument.getName());
}
};
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, CallableMemberDescriptor, CallableMemberDescriptor, DeclarationDescriptor> VIRTUAL_MEMBER_HIDDEN = PsiElementOnlyDiagnosticFactory3.create(ERROR, "''{0}'' hides ''{1}'' in class {2} and needs 'override' modifier", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory1<JetSimpleNameExpression, VariableDescriptor> UNINITIALIZED_VARIABLE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable ''{0}'' must be initialized", NAME);
@@ -217,7 +210,7 @@ public interface Errors {
SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed");
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Classifier {0} does not have a class object", NAME);
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Please specify constructor invocation; classifier {0} does not have a class object", NAME);
SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
SimpleDiagnosticFactory HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY = SimpleDiagnosticFactory.create(ERROR, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext' property");
@@ -27,15 +27,17 @@ public class FunctionSignatureDiagnosticFactory extends DiagnosticFactoryWithMes
// primary constructor
JetClass klass = (JetClass) jetDeclaration;
PsiElement nameAsDeclaration = klass.getNameIdentifier();
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (nameAsDeclaration == null || primaryConstructorParameterList == null) {
if (nameAsDeclaration == null){
return klass.getTextRange();
} else {
return new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
);
}
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList == null) {
return nameAsDeclaration.getTextRange();
}
return new TextRange(
nameAsDeclaration.getTextRange().getStartOffset(),
primaryConstructorParameterList.getTextRange().getEndOffset()
);
} else {
// safe way
return jetDeclaration.getTextRange();
@@ -120,32 +120,26 @@ public class BodyResolver {
context.getTrace().report(SUPERTYPE_INITIALIZED_IN_TRAIT.on(node));
}
JetTypeReference typeReference = call.getTypeReference();
if (typeReference != null) {
if (descriptor.getUnsubstitutedPrimaryConstructor() != null) {
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
context.getTrace(), scopeForConstructor,
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
if (results.isSuccess()) {
JetType supertype = results.getResultingDescriptor().getReturnType();
recordSupertype(typeReference, supertype);
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
if (classDescriptor != null) {
if (classDescriptor.getKind() == ClassKind.TRAIT) {
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(node));
}
}
}
else {
recordSupertype(typeReference, context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference));
if (typeReference == null) return;
if (descriptor.getUnsubstitutedPrimaryConstructor() == null) {
assert descriptor.getKind() == ClassKind.TRAIT;
return;
}
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
context.getTrace(), scopeForConstructor,
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
if (results.isSuccess()) {
JetType supertype = results.getResultingDescriptor().getReturnType();
recordSupertype(typeReference, supertype);
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
if (classDescriptor != null) {
if (classDescriptor.getKind() == ClassKind.TRAIT) {
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(node));
}
}
else if (descriptor.getKind() != ClassKind.TRAIT) {
JetType supertype = context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference);
recordSupertype(typeReference, supertype);
assert valueArgumentList != null;
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL.on(valueArgumentList, jetClass));
}
}
else {
recordSupertype(typeReference, context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference));
}
}
@@ -159,7 +153,18 @@ public class BodyResolver {
if (classDescriptor != null) {
if (descriptor.getKind() != ClassKind.TRAIT) {
if (classDescriptor.hasConstructors() && !ErrorUtils.isError(classDescriptor.getTypeConstructor()) && classDescriptor.getKind() != ClassKind.TRAIT) {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
boolean hasConstructorWithoutParams = false;
for (ConstructorDescriptor constructor : classDescriptor.getConstructors()) {
if (constructor.getValueParameters().isEmpty()) {
hasConstructorWithoutParams = true;
}
}
if (!hasConstructorWithoutParams) {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
}
else {
context.getTrace().report(SUPERTYPE_NOT_INITIALIZED_DEFAULT.on(specifier));
}
}
}
}
@@ -287,9 +292,7 @@ public class BodyResolver {
final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
assert containingClass != null : "This must be guaranteed by the parser";
if (!containingClass.hasPrimaryConstructor()) {
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
context.getTrace().report(SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY.on(declaration.getNameNode()));
}
else {
@@ -143,11 +143,12 @@ public class DeclarationResolver {
}
private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) {
if (!klass.hasPrimaryConstructor()) return;
if (classDescriptor.getKind() == ClassKind.TRAIT) {
// context.getTrace().getErrorHandler().genericError(klass.getPrimaryConstructorParameterList().getNode(), "A trait may not have a constructor");
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(klass.getPrimaryConstructorParameterList()));
JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
if (primaryConstructorParameterList != null) {
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList));
}
if (!klass.hasPrimaryConstructor()) return;
}
// TODO : not all the parameters are real properties
@@ -34,8 +34,6 @@ public class DeclarationsChecker {
}
public void process() {
checkIfPrimaryConstructorIsNecessary();
Map<JetClass, MutableClassDescriptor> classes = context.getClasses();
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
JetClass aClass = entry.getKey();
@@ -77,25 +75,6 @@ public class DeclarationsChecker {
}
private void checkIfPrimaryConstructorIsNecessary() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
MutableClassDescriptor classDescriptor = entry.getValue();
JetClass jetClass = entry.getKey();
if (!context.completeAnalysisNeeded(jetClass)) return;
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null && !(classDescriptor.getKind() == ClassKind.TRAIT)) {
for (PropertyDescriptor propertyDescriptor : classDescriptor.getProperties()) {
if (context.getTrace().getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) {
PsiElement nameIdentifier = jetClass.getNameIdentifier();
if (nameIdentifier != null) {
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY.on(jetClass, nameIdentifier, propertyDescriptor));
}
break;
}
}
}
}
}
private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) {
checkOpenMembers(aClass, classDescriptor);
checkTraitModifiers(aClass);
@@ -246,12 +225,6 @@ public class DeclarationsChecker {
else if (!backingFieldRequired) {
context.getTrace().report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
}
else if (classDescriptor != null && classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
assert classElement instanceof JetClass;
context.getTrace().report(PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR.on(property, initializer, (JetClass) classElement));
}
}
protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) {
@@ -788,7 +788,7 @@ public class DescriptorResolver {
@Nullable
public ConstructorDescriptorImpl resolvePrimaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass classElement) {
if (!classElement.hasPrimaryConstructor()) return null;
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY && !classElement.hasPrimaryConstructor()) return null;
return createConstructorDescriptor(
scope,
classDescriptor,
@@ -105,7 +105,7 @@ public class TypeHierarchyResolver {
@Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope);
final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope, ClassKind.OBJECT);
context.getTrace().record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor);
}
@@ -114,32 +114,27 @@ public class TypeHierarchyResolver {
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor();
assert classObjectDescriptor != null : enumEntry.getParent().getText();
if (enumEntry.getPrimaryConstructorParameterList() == null) {
MutableClassDescriptor classDescriptor = createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic);
context.getObjects().remove(enumEntry);
context.getClasses().put(enumEntry, classDescriptor);
}
else {
// TODO : Special kind for enum entry classes?
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), classObjectDescriptor, outerScope, ClassKind.CLASS);
visitClassOrObject(
enumEntry,
(Map) context.getClasses(),
mutableClassDescriptor
);
classObjectDescriptor.addClassifierDescriptor(mutableClassDescriptor);
createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic, ClassKind.ENUM_ENTRY);
return;
}
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), classObjectDescriptor, outerScope, ClassKind.ENUM_ENTRY);
visitClassOrObject(
enumEntry,
(Map) context.getClasses(),
mutableClassDescriptor
);
classObjectDescriptor.addClassifierDescriptor(mutableClassDescriptor);
}
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration,
@NotNull NamespaceLike owner, JetScope scope) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, ClassKind.OBJECT) {
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner, JetScope scope, ClassKind classKind) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, scope, classKind) {
@Override
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
return ClassObjectStatus.NOT_ALLOWED;
}
};
visitClassOrObject(declaration, (Map) context.getObjects(), mutableClassDescriptor);
Map<JetClassOrObject, MutableClassDescriptor> map = classKind == ClassKind.OBJECT ? (Map) context.getObjects() : (Map) context.getClasses();
visitClassOrObject(declaration, map, mutableClassDescriptor);
createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
owner.addObjectDescriptor(mutableClassDescriptor);
context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
@@ -176,7 +171,7 @@ public class TypeHierarchyResolver {
public void visitClassObject(JetClassObject classObject) {
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
if (objectDeclaration != null) {
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic));
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic, ClassKind.OBJECT));
switch (status) {
case DUPLICATE:
context.getTrace().report(MANY_CLASS_OBJECTS.on(classObject));
@@ -80,7 +80,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (classifier != null) {
context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
context.trace.record(REFERENCE_TARGET, expression, classifier);
return ErrorUtils.createErrorType("No class object in " + expression.getReferencedName());
return classifier.getDefaultType();
}
temporaryTrace.commit();
return result[0];
+1 -1
View File
@@ -4,7 +4,7 @@ open class C {
open fun f(): Any = "C f"
}
class D() : C {
class D() : C() {
override fun f(): String = "D f"
}
@@ -3,7 +3,7 @@ abstract open class Default {
}
class MyInt() {
class object : Default {
class object : Default() {
override fun defaultValue(): Int = 610
}
}
@@ -2,7 +2,7 @@ open class Foo {
fun xyzzy(): String = "xyzzy"
}
class Bar(): Foo {
class Bar(): Foo() {
fun test(): String = xyzzy()
}
@@ -6,7 +6,7 @@ trait ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value
}
class SmartArrayList() : ALE<String>, AL<String> {
class SmartArrayList() : ALE<String>, AL<String>() {
}
fun box() : String {
@@ -3,7 +3,7 @@ package boundsWithSubstitutors
open class A<T>
class B<X : A<X>>()
class C : A<C>
class C : A<C>()
val a = B<C>()
val a1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>()
@@ -1,14 +1,14 @@
open class NoC
class NoC1 : NoC
class NoC1 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>NoC<!>
class WithC0() : NoC<!NO_CONSTRUCTOR!>()<!>
open class WithC1() : NoC
class NoC2 : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!>
class NoC3 : WithC1<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>
class WithC2() : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!>
class WithC0() : NoC()
open class WithC1() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>NoC<!>
class NoC2 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>WithC1<!>
class NoC3 : WithC1()
class WithC2() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>WithC1<!>
class NoPC {
<!SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY!>this<!>() {}
class <!CONFLICTING_OVERLOADS!>NoPC<!> {
<!CONFLICTING_OVERLOADS!><!SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>() {}<!>
}
class WithPC0() {
@@ -28,7 +28,7 @@ class WithPC1(a : Int) {
}
class Foo() : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>WithPC0<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SYNTAX!>this<!>() {
class Foo() : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, FINAL_SUPERTYPE!>WithPC0<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST, SYNTAX!>this<!>() {
}
@@ -42,9 +42,9 @@ class WithCPI(x : Int) {
val xy : Int = x
}
class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>NoCPI<!> {
val a = <!PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR!>1<!>
class NoCPI {
val a = 1
var ab = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!>
get() = 1
set(v) {}
}
}
@@ -40,14 +40,14 @@ abstract class Iteratee<in I, out O> {
abstract fun done() : O
}
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> {
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O>() {
override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj)
override val isDone = true
override val result = obj
override fun done() = obj
}
abstract class Sum() : Iteratee<Int, Int> {
abstract class Sum() : Iteratee<Int, Int>() {
override fun process(item : Int) : Iteratee<Int, Int> {
return foobar.done<Int>(item);
}
@@ -71,7 +71,7 @@ package localObjects
fun test() {
A.x
val b = object : Foo {
val b = object : Foo() {
}
b.foo()
@@ -11,7 +11,7 @@ package override.normal
}
open class MyClass() : MyTrait, MyAbstractClass {
open class MyClass() : MyTrait, MyAbstractClass() {
override fun foo() {}
override fun bar() {}
@@ -21,21 +21,21 @@ package override.normal
class MyChildClass() : MyClass() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass<!> : MyTrait, MyAbstractClass() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!>() : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!>() : MyTrait, MyAbstractClass() {
override fun foo() {}
override val pr : Unit = #()
override val prr : Unit = #()
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!>() : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass3<!>() : MyTrait, MyAbstractClass() {
override fun bar() {}
override val pr : Unit = #()
override val prr : Unit = #()
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!>() : MyTrait, MyAbstractClass {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass4<!>() : MyTrait, MyAbstractClass() {
fun <!VIRTUAL_MEMBER_HIDDEN!>foo<!>() {}
val <!VIRTUAL_MEMBER_HIDDEN, MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>pr<!> : Unit
<!NOTHING_TO_OVERRIDE!>override<!> fun other() {}
@@ -65,7 +65,7 @@ package override.generics
val p : T
}
open class MyGenericClass<T>(t : T) : MyTrait<T>, MyAbstractClass<T>, MyProps<T> {
open class MyGenericClass<T>(t : T) : MyTrait<T>, MyAbstractClass<T>(), MyProps<T> {
override fun foo(t: T) = t
override fun bar(t: T) = t
override val p : T = t
@@ -81,31 +81,31 @@ package override.generics
override val p : T = t
}
open class MyClass() : MyTrait<Int>, MyAbstractClass<String> {
open class MyClass() : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i
override fun bar(s: String) = s
override val pr : String = "1"
}
abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> {
abstract class MyAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i
override fun bar(s: String) = s
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T> {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R> {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass1<!><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalGenericClass2<!><T, R>(r : R) : MyTrait<T>, MyAbstractClass<R>() {
<!NOTHING_TO_OVERRIDE!>override<!> fun foo(r: R) = r
<!NOTHING_TO_OVERRIDE!>override<!> val <T> pr : R = r
}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String> {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String> {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass1<!> : MyTrait<Int>, MyAbstractClass<String>() {}
abstract class MyLegalAbstractClass1 : MyTrait<Int>, MyAbstractClass<String>() {}
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> {
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>MyIllegalClass2<!><T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
}
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int> {
abstract class MyLegalAbstractClass2<T>(t : T) : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
val <R> pr : T = t
@@ -1,4 +1,6 @@
class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>X<!> {
//+JDK
class X {
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int
}
@@ -10,5 +12,20 @@ class Y1 {
val x : Int get() = 1
}
class Z : Y<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!> {
class Z : Y() {
}
//KT-650 Prohibit creating class without constructor.
class MyIterable<T> : Iterable<T>
{
override fun iterator(): Iterator<T> = MyIterator()
class MyIterator : Iterator<T>
{
override val hasNext: Boolean = false
override fun next(): T {
throw UnsupportedOperationException()
}
}
}
@@ -39,13 +39,12 @@ trait Test6 : <!FINAL_SUPERTYPE!>C1<!> {}
class CTest1() : OC1() {}
class CTest2 : C2 {}
class CTest2 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>C2<!> {}
class CTest3 : C2, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {}
class CTest3 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT!>C2<!>, <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST!>C3<!> {}
class CTest4 : T1 {}
class CTest5 : T1, <!SUPERTYPE_APPEARS_TWICE!>T1<!> {}
class CTest6 : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>C1<!> {}
class CTest6 : <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, FINAL_SUPERTYPE!>C1<!> {}
@@ -7,5 +7,5 @@ trait Foo<!CONSTRUCTOR_IN_TRAIT!>()<!> : bar<!SUPERTYPE_INITIALIZED_IN_TRAIT!>()
trait Foo2 : bar, Foo {
}
open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {}
open class Foo12 : bar<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>, <!SUPERTYPE_NOT_INITIALIZED, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {}
open class Foo1() : bar(), <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!>, Foo, <!SUPERTYPE_APPEARS_TWICE!>Foo<!><!CONSTRUCTOR_IN_TRAIT!>()<!> {}
open class Foo12 : bar(), <!SUPERTYPE_NOT_INITIALIZED_DEFAULT, MANY_CLASSES_IN_SUPERTYPE_LIST, SUPERTYPE_APPEARS_TWICE!>bar<!> {}
@@ -5,7 +5,7 @@ import java.util.List;
open class A
class B : A
class B : A()
fun ff(l: Collection<B>) = l is List<out A>
@@ -1,4 +1,4 @@
// JET-11 Redeclaration & Forward reference for classes cause an exception
open class <!REDECLARATION!>NoC<!>
class NoC1 : NoC
class NoC1 : NoC()
open class <!REDECLARATION!>NoC<!>
@@ -7,10 +7,10 @@ open class A {
open fun foo() {}
}
open class B : A {
open class B : A() {
override fun foo() {}
}
open class C : B {
open class C : B() {
override fun foo() {}
}
+2 -2
View File
@@ -1,12 +1,12 @@
~A~class A {
~B~class B {
~B()~this() {}
~B()~this(i: Int) {}
}
~foo~fun foo(~foo.a~a : `std::Char`Char) = `foo.a`a`:std::Char`
~fooB~fun fooB() = `foo`foo('1')`:std::Char`
~foo.1~fun foo() : Int = (1.`std::Int.plus(Int)`plus(1))`:std::Int`
~foo1~fun foo1() : `B`B = `B()`B()`:B`
~foo1~fun foo1() : `B`B = `B`B()`:B`
~A.a~val a : `std::Int`Int
}
+1 -1
View File
@@ -11,5 +11,5 @@ package Jet86
}
val a = `A`A.`A.x`x
val c = `B`B.`!error`x
val c = `B`B.`B.x`x
val d = B().`B.x`x
@@ -8,7 +8,6 @@ fun f_plus(): Int {
}
~X~class X<~T~T> {
~X()~this() {}
fun foo(a : `T`T) : `X`X<`T`T>{}
~plus~fun plus(t : `T`T) : Int {}
~minus~fun minus(t : String) : Int {}
@@ -23,7 +22,7 @@ fun f_plus(): Int {
~t~fun <~t.T~T> t(~t.t~t : `t.T`T) : `t.T`T {
`t`t<Int>(1)`:std::Int`
`t`t<`t.T`T>(`t.t`t)`:t.T`
`X()`X<`t.T`T>()
`X`X<`t.T`T>()
1 `std::Int.plus(Int)`+ 1
1 `std::Int.plus(Int)`+= 1
X<String>() `plus`+ "1"
@@ -50,7 +49,6 @@ fun f_plus(): Int {
}
~Bar~class Bar : Foo {
~Bar()~this() {}
~not~fun not() : String {}
~inc~fun inc() : Bar
~dec~fun dec() : Bar
@@ -61,7 +59,7 @@ fun f_plus(): Int {
fun <T> tt(t : T) : T {
val x : List<Int> = 0
x`java::java.util.List.get()`[1]
val foo = `Bar()`Bar()
val foo = `Bar`Bar()
foo`!!`[null, 1]
foo`get2`[1, 1]
foo`get1`[1]
@@ -93,12 +93,6 @@ public class QuickFixes {
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
JetIntentionActionFactory<JetClass> addPrimaryConstructorFactory = AddPrimaryConstructorFix.createFactory();
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addPrimaryConstructorFactory, DiagnosticParameters.CLASS));
add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory);
JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS));
@@ -1,7 +1,7 @@
open class A<T>
class B<X : A<X>>()
class C : A<C>
class C : A<C>()
val a = B<C>()
val a1 = B<<error>Int</error>>()
+3 -3
View File
@@ -2,11 +2,11 @@ package html
import java.util.*
abstract class Factory<T> {
abstract fun create() : T
trait Factory<T> {
fun create() : T
}
abstract class Element
trait Element
class TextElement(val text : String) : Element
+9 -9
View File
@@ -1,15 +1,15 @@
open class NoC
class NoC1 : NoC
class NoC1 : NoC()
class WithC0() : NoC<error>()</error>
open class WithC1() : NoC
class WithC0() : NoC()
open class WithC1() : NoC()
class NoC2 : <error>WithC1</error>
class NoC3 : WithC1<error>()</error>
class NoC3 : WithC1()
class WithC2() : <error>WithC1</error>
class NoPC {
<error>this</error>() {}
class <error>NoPC</error> {
<error><error>this</error>() {}</error>
}
class WithPC0() {
@@ -29,7 +29,7 @@ class WithPC1(a : Int) {
}
class Foo() : <error>WithPC0</error>, <error>this</error>() {
class Foo() : <error>WithPC0</error>(), <error>this</error>() {
}
@@ -43,8 +43,8 @@ class WithCPI(x : Int) {
val xy : Int = x
}
class <error>NoCPI</error> {
val a = <error>1</error>
class NoCPI {
val a = 1
var ab = <error>1</error>
get() = 1
set(v) {}
+1 -1
View File
@@ -8,7 +8,7 @@
fun test() {
A.x
val b = object : Foo {
val b = object : Foo() {
}
b.foo()
+2 -2
View File
@@ -14,14 +14,14 @@ abstract class Iteratee<in I, out O> {
abstract fun done() : O
}
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O> {
class StrangeIterateeImpl<in I, out O>(val obj: O) : Iteratee<I, O>() {
override fun process(item: I): Iteratee<I, O> = StrangeIterateeImpl<I, O>(obj)
override val isDone = true
override val result = obj
override fun done() = obj
}
abstract class Sum() : Iteratee<Int, Int> {
abstract class Sum() : Iteratee<Int, Int>() {
override fun process(item : Int) : Iteratee<Int, Int> {
return a.done<Int>(item);
}
+7 -7
View File
@@ -8,29 +8,29 @@ package override
abstract fun bar()
}
open class MyClass : MyTrait, MyAbstractClass {
open class MyClass : MyTrait, MyAbstractClass() {
override fun foo() {}
override fun bar() {}
}
class MyChildClass : MyClass {}
class MyChildClass : MyClass() {}
class <error>MyIllegalClass</error> : MyTrait, MyAbstractClass {}
class <error>MyIllegalClass</error> : MyTrait, MyAbstractClass() {}
class <error>MyIllegalClass2</error> : MyTrait, MyAbstractClass {
class <error>MyIllegalClass2</error> : MyTrait, MyAbstractClass() {
override fun foo() {}
}
class <error>MyIllegalClass3</error> : MyTrait, MyAbstractClass {
class <error>MyIllegalClass3</error> : MyTrait, MyAbstractClass() {
override fun bar() {}
}
class <error>MyIllegalClass4</error> : MyTrait, MyAbstractClass {
class <error>MyIllegalClass4</error> : MyTrait, MyAbstractClass() {
fun <error>foo</error>() {}
<error>override</error> fun other() {}
}
class MyChildClass1 : MyClass {
class MyChildClass1 : MyClass() {
fun <error>foo</error>() {}
override fun bar() {}
}
@@ -6,30 +6,30 @@
abstract fun bar(t: T) : T
}
open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T> {
open class MyGenericClass<T> : MyTrait<T>, MyAbstractClass<T>() {
override fun foo(t: T) = t
override fun bar(t: T) = t
}
class MyChildClass : MyGenericClass<Int> {}
class MyChildClass1<T> : MyGenericClass<T> {}
class MyChildClass2<T> : MyGenericClass<T> {
class MyChildClass : MyGenericClass<Int>() {}
class MyChildClass1<T> : MyGenericClass<T>() {}
class MyChildClass2<T> : MyGenericClass<T>() {
fun <error>foo</error>(t: T) = t
override fun bar(t: T) = t
}
open class MyClass : MyTrait<Int>, MyAbstractClass<String> {
open class MyClass : MyTrait<Int>, MyAbstractClass<String>() {
override fun foo(i: Int) = i
override fun bar(s: String) = s
}
class <error>MyIllegalGenericClass1</error><T> : MyTrait<T>, MyAbstractClass<T> {}
class <error>MyIllegalGenericClass2</error><T, R> : MyTrait<T>, MyAbstractClass<R> {
class <error>MyIllegalGenericClass1</error><T> : MyTrait<T>, MyAbstractClass<T>() {}
class <error>MyIllegalGenericClass2</error><T, R> : MyTrait<T>, MyAbstractClass<R>() {
<error>override</error> fun foo(r: R) = r
}
class <error>MyIllegalClass1</error> : MyTrait<Int>, MyAbstractClass<String> {}
class <error>MyIllegalClass1</error> : MyTrait<Int>, MyAbstractClass<String>() {}
class <error>MyIllegalClass2</error><T> : MyTrait<Int>, MyAbstractClass<Int> {
class <error>MyIllegalClass2</error><T> : MyTrait<Int>, MyAbstractClass<Int>() {
fun foo(t: T) = t
fun bar(t: T) = t
}
@@ -1,4 +1,4 @@
class <error>X</error> {
class X {
val <error>x</error> : Int
}
@@ -10,5 +10,5 @@ class Y1 {
val x : Int get() = 1
}
class Z : Y<error>()</error> {
class Z : Y() {
}
@@ -39,9 +39,9 @@ trait Test6 : <error>C1</error> {}
class CTest1() : OC1() {}
class CTest2 : C2 {}
class CTest2 : <error>C2</error> {}
class CTest3 : C2, <error>C3</error> {}
class CTest3 : <error>C2</error>, <error>C3</error> {}
class CTest4 : T1 {}
+1 -1
View File
@@ -8,4 +8,4 @@ trait Foo2 : bar, Foo {
}
open class Foo1() : bar(), <error>bar</error>, Foo, <error>Foo</error><error>()</error> {}
open class Foo12 : bar<error>()</error>, <error>bar</error> {}
open class Foo12 : bar(), <error>bar</error> {}
+1 -1
View File
@@ -1,4 +1,4 @@
// JET-11 Redeclaration & Forward reference for classes cause an exception
open class <error>NoC</error>
class NoC1 : NoC
class NoC1 : NoC()
open class <error>NoC</error>
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A() {
var i : Int = <caret>1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A<caret>() {
var i : Int = 1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A {
var i : Int = <caret>1
}
@@ -1,6 +0,0 @@
// "Add primary constructor to A" "true"
package a
class A<caret> {
var i : Int = 1
}