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
+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]