Use more specific error for secondary constructor bodies in inline classes
- Also, this error allows IDE to provide quick-fix that changes language version in a project that simplifies the adoption - There is no point in changing K2 part as there this feature will be enabled by default ^KT-56224 Fixed
This commit is contained in:
committed by
Space Team
parent
f3e022e4ca
commit
c586d7a03a
+6
@@ -18356,6 +18356,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedConstructorsBodyInKotlinPre19.kt")
|
||||
public void testReservedConstructorsBodyInKotlinPre19() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt")
|
||||
public void testReservedMembersAndConstructsInsideInlineClass() throws Exception {
|
||||
|
||||
+6
@@ -18362,6 +18362,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedConstructorsBodyInKotlinPre19.kt")
|
||||
public void testReservedConstructorsBodyInKotlinPre19() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt")
|
||||
public void testReservedMembersAndConstructsInsideInlineClass() throws Exception {
|
||||
|
||||
+6
@@ -18356,6 +18356,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedConstructorsBodyInKotlinPre19.kt")
|
||||
public void testReservedConstructorsBodyInKotlinPre19() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt")
|
||||
public void testReservedMembersAndConstructsInsideInlineClass() throws Exception {
|
||||
|
||||
@@ -426,7 +426,6 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> RESERVED_MEMBER_INSIDE_VALUE_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
-1
@@ -806,7 +806,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(VALUE_CLASS_CANNOT_EXTEND_CLASSES, "Value class cannot extend classes");
|
||||
MAP.put(VALUE_CLASS_CANNOT_BE_RECURSIVE, "Value class cannot be recursive");
|
||||
MAP.put(MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER, "Default parameters are not supported in the primary constructor of a multi-field value class");
|
||||
MAP.put(SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS, "Secondary constructors with bodies are reserved for for future releases");
|
||||
MAP.put(RESERVED_MEMBER_INSIDE_VALUE_CLASS, "Member with the name ''{0}'' is reserved for future releases", STRING);
|
||||
MAP.put(TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS, "Type arguments for typed value class equals must be only star projections");
|
||||
MAP.put(INNER_CLASS_INSIDE_VALUE_CLASS, "Value class cannot have inner classes");
|
||||
|
||||
+6
-1
@@ -265,7 +265,12 @@ class ReservedMembersAndConstructsForValueClass : DeclarationChecker {
|
||||
val bodyExpression = secondaryConstructor.bodyExpression
|
||||
if (secondaryConstructor.hasBlockBody() && bodyExpression is KtBlockExpression) {
|
||||
val lBrace = bodyExpression.lBrace ?: return
|
||||
context.trace.report(Errors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS.on(lBrace))
|
||||
context.trace.report(
|
||||
Errors.UNSUPPORTED_FEATURE.on(
|
||||
lBrace,
|
||||
LanguageFeature.ValueClassesSecondaryConstructorWithBody to context.languageVersionSettings
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody
|
||||
// WITH_STDLIB
|
||||
|
||||
@JvmInline
|
||||
value class Foo(val x: String) {
|
||||
constructor(i: Int) : this(i.toString()) <!SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS!>{
|
||||
println(i)
|
||||
}<!>
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody
|
||||
// WITH_STDLIB
|
||||
|
||||
@JvmInline
|
||||
value class Foo(val x: String) {
|
||||
constructor(i: Int) : this(i.toString()) <!UNSUPPORTED_FEATURE!>{<!>
|
||||
println(i)
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class Foo {
|
||||
public constructor Foo(/*0*/ i: kotlin.Int)
|
||||
public constructor Foo(/*0*/ x: kotlin.String)
|
||||
public final val x: kotlin.String
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+6
@@ -18362,6 +18362,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedConstructorsBodyInKotlinPre19.kt")
|
||||
public void testReservedConstructorsBodyInKotlinPre19() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt")
|
||||
public void testReservedMembersAndConstructsInsideInlineClass() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user