Support non-public inline class constructors
#KT-28056 Fixed
This commit is contained in:
Generated
+5
@@ -13567,6 +13567,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/conformToComparableAndCallInterfaceMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorImplVisibility.kt")
|
||||
public void testConstructorImplVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/constructorImplVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctBoxingForBranchExpressions.kt")
|
||||
public void testCorrectBoxingForBranchExpressions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt");
|
||||
|
||||
@@ -352,7 +352,6 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_TOP_LEVEL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_NOT_FINAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtElement> INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtParameter> INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtProperty> PROPERTY_WITH_BACKING_FIELD_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
-1
@@ -706,7 +706,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INLINE_CLASS_NOT_TOP_LEVEL, "Inline classes are only allowed on top level");
|
||||
MAP.put(INLINE_CLASS_NOT_FINAL, "Inline classes can be only final");
|
||||
MAP.put(ABSENCE_OF_PRIMARY_CONSTRUCTOR_FOR_INLINE_CLASS, "Primary constructor is required for inline class");
|
||||
MAP.put(NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS, "Primary constructor of inline class must be public");
|
||||
MAP.put(INLINE_CLASS_CONSTRUCTOR_WRONG_PARAMETERS_SIZE, "Inline class must have exactly one primary constructor parameter");
|
||||
MAP.put(INLINE_CLASS_CONSTRUCTOR_NOT_FINAL_READ_ONLY_PARAMETER, "Inline class primary constructor must have only final read-only (val) property parameter");
|
||||
MAP.put(PROPERTY_WITH_BACKING_FIELD_INSIDE_INLINE_CLASS, "Inline class cannot have properties with backing fields");
|
||||
|
||||
-6
@@ -46,12 +46,6 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
return
|
||||
}
|
||||
|
||||
val primaryConstructorVisibility = descriptor.unsubstitutedPrimaryConstructor?.visibility
|
||||
if (primaryConstructorVisibility != null && primaryConstructorVisibility != DescriptorVisibilities.PUBLIC) {
|
||||
trace.report(Errors.NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS.on(primaryConstructor.visibilityModifier() ?: inlineKeyword))
|
||||
return
|
||||
}
|
||||
|
||||
val baseParameter = primaryConstructor.valueParameters.singleOrNull()
|
||||
if (baseParameter == null) {
|
||||
(primaryConstructor.valueParameterList ?: declaration).let {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
inline class IC1 public constructor(val i: Int)
|
||||
inline class IC11 internal constructor(val i: Int)
|
||||
inline class IC2 private constructor(val i: Int)
|
||||
inline class IC4 protected constructor(val i: Int)
|
||||
|
||||
fun box(): String {
|
||||
if (!Modifier.isPublic(IC1::class.java.declaredMethods.single { it.name == "constructor-impl" }.modifiers)) return "FAIL 1"
|
||||
if (!Modifier.isPublic(IC11::class.java.declaredMethods.single { it.name == "constructor-impl" }.modifiers)) return "FAIL 1"
|
||||
if (!Modifier.isPrivate(IC2::class.java.declaredMethods.single { it.name == "constructor-impl" }.modifiers)) return "FAIL 2"
|
||||
if (!Modifier.isProtected(IC4::class.java.declaredMethods.single { it.name == "constructor-impl" }.modifiers)) return "FAIL 4"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class IC1 public constructor(val i: Int)
|
||||
inline class IC11 internal constructor(val i: Int)
|
||||
inline class IC2 private constructor(val i: Int)
|
||||
inline class IC4 protected constructor(val i: Int)
|
||||
|
||||
private inline class PIC1 public constructor(val i: Int)
|
||||
private inline class PIC11 internal constructor(val i: Int)
|
||||
private inline class PIC2 private constructor(val i: Int)
|
||||
private inline class PIC4 protected constructor(val i: Int)
|
||||
@@ -0,0 +1,143 @@
|
||||
@kotlin.Metadata
|
||||
public final class IC1 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): IC1
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class IC11 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): IC11
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class IC2 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): IC2
|
||||
private static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class IC4 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): IC4
|
||||
protected static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class PIC1 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): PIC1
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class PIC11 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): PIC11
|
||||
public static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class PIC2 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): PIC2
|
||||
private static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class PIC4 {
|
||||
// source: 'constructor.kt'
|
||||
private final field i: int
|
||||
private synthetic method <init>(p0: int): void
|
||||
public synthetic final static method box-impl(p0: int): PIC4
|
||||
protected static method constructor-impl(p0: int): int
|
||||
public method equals(p0: java.lang.Object): boolean
|
||||
public static method equals-impl(p0: int, p1: java.lang.Object): boolean
|
||||
public final static method equals-impl0(p0: int, p1: int): boolean
|
||||
public final method getI(): int
|
||||
public method hashCode(): int
|
||||
public static method hashCode-impl(p0: int): int
|
||||
public method toString(): java.lang.String
|
||||
public static method toString-impl(p0: int): java.lang.String
|
||||
public synthetic final method unbox-impl(): int
|
||||
}
|
||||
+3
-3
@@ -2,6 +2,6 @@
|
||||
|
||||
inline class ConstructorWithDefaultVisibility(val x: Int)
|
||||
inline class PublicConstructor public constructor(val x: Int)
|
||||
inline class InternalConstructor <!NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS!>internal<!> constructor(val x: Int)
|
||||
inline class ProtectedConstructor <!NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS!>protected<!> constructor(val x: Int)
|
||||
inline class PrivateConstructor <!NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS!>private<!> constructor(val x: Int)
|
||||
inline class InternalConstructor internal constructor(val x: Int)
|
||||
inline class ProtectedConstructor protected constructor(val x: Int)
|
||||
inline class PrivateConstructor private constructor(val x: Int)
|
||||
|
||||
+5
@@ -14967,6 +14967,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/conformToComparableAndCallInterfaceMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorImplVisibility.kt")
|
||||
public void testConstructorImplVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/constructorImplVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctBoxingForBranchExpressions.kt")
|
||||
public void testCorrectBoxingForBranchExpressions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt");
|
||||
|
||||
+5
@@ -867,6 +867,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorsWithDefaultParameterValues.kt")
|
||||
public void testConstructorsWithDefaultParameterValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/constructorsWithDefaultParameterValues.kt");
|
||||
|
||||
+5
@@ -14982,6 +14982,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/conformToComparableAndCallInterfaceMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorImplVisibility.kt")
|
||||
public void testConstructorImplVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/constructorImplVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctBoxingForBranchExpressions.kt")
|
||||
public void testCorrectBoxingForBranchExpressions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt");
|
||||
|
||||
+5
@@ -13567,6 +13567,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/conformToComparableAndCallInterfaceMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorImplVisibility.kt")
|
||||
public void testConstructorImplVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/constructorImplVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctBoxingForBranchExpressions.kt")
|
||||
public void testCorrectBoxingForBranchExpressions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/correctBoxingForBranchExpressions.kt");
|
||||
|
||||
+5
@@ -837,6 +837,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorsWithDefaultParameterValues.kt")
|
||||
public void testConstructorsWithDefaultParameterValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/constructorsWithDefaultParameterValues.kt");
|
||||
|
||||
Reference in New Issue
Block a user