Introduction of sealed classes

Sealed classes can be derived only by their own inner classes or objects.
Their constructors cannot be called explicitly, so compiler knows all their descendants.
Incompatible modifier checks (final, abstract). Impossible with interface, object, enum.
A pack of tests provided.
This commit is contained in:
Mikhail Glukhikh
2015-05-12 18:07:17 +03:00
parent 2dea17a3a9
commit 8d25c20169
42 changed files with 432 additions and 12 deletions
@@ -0,0 +1,52 @@
package
internal sealed class Sealed {
public constructor Sealed(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
internal object First : Sealed {
private constructor First()
internal final override /*1*/ /*fake_override*/ val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal open class NonFirst : Sealed {
public constructor NonFirst(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
internal final override /*1*/ /*fake_override*/ val x: kotlin.Int
internal final val y: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
internal object Fourth : Sealed {
private constructor Fourth()
internal final override /*1*/ /*fake_override*/ val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal object Second : Sealed.NonFirst {
private constructor Second()
internal final override /*1*/ /*fake_override*/ val x: kotlin.Int
internal final override /*1*/ /*fake_override*/ val y: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal object Third : Sealed.NonFirst {
private constructor Third()
internal final override /*1*/ /*fake_override*/ val x: kotlin.Int
internal final override /*1*/ /*fake_override*/ val y: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}