Sealed code generation: sealed is considered abstract, correct serialization
A pair of tests provided.
This commit is contained in:
@@ -132,7 +132,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
if (myClass instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) myClass;
|
||||
if (jetClass.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
|
||||
if (jetClass.hasModifier(JetTokens.ABSTRACT_KEYWORD) || jetClass.isSealed()) {
|
||||
isAbstract = true;
|
||||
}
|
||||
if (jetClass.isInterface()) {
|
||||
|
||||
@@ -64,6 +64,7 @@ public open class JetClass : JetClassOrObject {
|
||||
?: (findChildByType<PsiElement>(JetTokens.TRAIT_KEYWORD) != null || findChildByType<PsiElement>(JetTokens.INTERFACE_KEYWORD) != null)
|
||||
|
||||
public fun isEnum(): Boolean = hasModifier(JetTokens.ENUM_KEYWORD)
|
||||
public fun isSealed(): Boolean = hasModifier(JetTokens.SEALED_KEYWORD)
|
||||
public fun isInner(): Boolean = hasModifier(JetTokens.INNER_KEYWORD)
|
||||
|
||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
sealed class Season {
|
||||
object Warm: Season()
|
||||
object Cold: Season()
|
||||
}
|
||||
|
||||
fun foo(): Season = Season.Warm
|
||||
|
||||
fun box() = when(foo()) {
|
||||
Season.Warm -> "OK"
|
||||
Season.Cold -> "Fail: Cold, should be Warm"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
sealed class Season {
|
||||
class Warm: Season()
|
||||
class Cold: Season()
|
||||
}
|
||||
|
||||
fun foo(): Season = Season.Warm()
|
||||
|
||||
fun box() = when(foo()) {
|
||||
is Season.Warm -> "OK"
|
||||
is Season.Cold -> "Fail: Cold, should be Warm"
|
||||
}
|
||||
+21
@@ -6581,6 +6581,27 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/sealed")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Sealed extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInSealed() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/sealed"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("objects.kt")
|
||||
public void testObjects() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/sealed/objects.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/sealed/simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/secondaryConstructors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -29,6 +29,10 @@ public final class DebugProtoBuf {
|
||||
* <code>ABSTRACT = 2;</code>
|
||||
*/
|
||||
ABSTRACT(2, 2),
|
||||
/**
|
||||
* <code>SEALED = 3;</code>
|
||||
*/
|
||||
SEALED(3, 3),
|
||||
;
|
||||
|
||||
/**
|
||||
@@ -47,6 +51,10 @@ public final class DebugProtoBuf {
|
||||
* <code>ABSTRACT = 2;</code>
|
||||
*/
|
||||
public static final int ABSTRACT_VALUE = 2;
|
||||
/**
|
||||
* <code>SEALED = 3;</code>
|
||||
*/
|
||||
public static final int SEALED_VALUE = 3;
|
||||
|
||||
|
||||
public final int getNumber() { return value; }
|
||||
@@ -56,6 +64,7 @@ public final class DebugProtoBuf {
|
||||
case 0: return FINAL;
|
||||
case 1: return OPEN;
|
||||
case 2: return ABSTRACT;
|
||||
case 3: return SEALED;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
@@ -17092,11 +17101,11 @@ public final class DebugProtoBuf {
|
||||
"ION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002" +
|
||||
"\022\017\n\013SYNTHESIZED\020\003\":\n\014CallableKind\022\007\n\003FUN" +
|
||||
"\020\000\022\007\n\003VAL\020\001\022\007\n\003VAR\020\002\022\017\n\013CONSTRUCTOR\020\003*\005\010" +
|
||||
"d\020\310\001*-\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n",
|
||||
"\010ABSTRACT\020\002*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022" +
|
||||
"\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022" +
|
||||
"\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005B\022B\rDebug" +
|
||||
"ProtoBuf\210\001\000"
|
||||
"d\020\310\001*9\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n",
|
||||
"\010ABSTRACT\020\002\022\n\n\006SEALED\020\003*b\n\nVisibility\022\014\n" +
|
||||
"\010INTERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022" +
|
||||
"\n\n\006PUBLIC\020\003\022\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCA" +
|
||||
"L\020\005B\022B\rDebugProtoBuf\210\001\000"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
|
||||
@@ -288,6 +288,7 @@ enum Modality {
|
||||
FINAL = 0x00;
|
||||
OPEN = 0x01;
|
||||
ABSTRACT = 0x02;
|
||||
SEALED = 0x03;
|
||||
}
|
||||
|
||||
enum Visibility {
|
||||
|
||||
@@ -170,6 +170,8 @@ public class Flags {
|
||||
return ProtoBuf.Modality.OPEN;
|
||||
case ABSTRACT:
|
||||
return ProtoBuf.Modality.ABSTRACT;
|
||||
case SEALED:
|
||||
return ProtoBuf.Modality.SEALED;
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown modality: " + modality);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ public final class ProtoBuf {
|
||||
* <code>ABSTRACT = 2;</code>
|
||||
*/
|
||||
ABSTRACT(2, 2),
|
||||
/**
|
||||
* <code>SEALED = 3;</code>
|
||||
*/
|
||||
SEALED(3, 3),
|
||||
;
|
||||
|
||||
/**
|
||||
@@ -47,6 +51,10 @@ public final class ProtoBuf {
|
||||
* <code>ABSTRACT = 2;</code>
|
||||
*/
|
||||
public static final int ABSTRACT_VALUE = 2;
|
||||
/**
|
||||
* <code>SEALED = 3;</code>
|
||||
*/
|
||||
public static final int SEALED_VALUE = 3;
|
||||
|
||||
|
||||
public final int getNumber() { return value; }
|
||||
@@ -56,6 +64,7 @@ public final class ProtoBuf {
|
||||
case 0: return FINAL;
|
||||
case 1: return OPEN;
|
||||
case 2: return ABSTRACT;
|
||||
case 3: return SEALED;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ fun modality(modality: ProtoBuf.Modality) = when (modality) {
|
||||
ProtoBuf.Modality.FINAL -> Modality.FINAL
|
||||
ProtoBuf.Modality.OPEN -> Modality.OPEN
|
||||
ProtoBuf.Modality.ABSTRACT -> Modality.ABSTRACT
|
||||
ProtoBuf.Modality.SEALED -> Modality.SEALED
|
||||
}
|
||||
|
||||
fun visibility(visibility: ProtoBuf.Visibility) = when (visibility) {
|
||||
|
||||
Reference in New Issue
Block a user