FE: Warn about generic inline class parameter in LV < 1.8
#KT-54192 Fixed
This commit is contained in:
+6
@@ -33418,6 +33418,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithForbiddenUnderlyingTypeMultiField.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithUniversal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassWithGenericUnderlyingTypeNoFeature.kt")
|
||||
public void testValueClassWithGenericUnderlyingTypeNoFeature() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithGenericUnderlyingTypeNoFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassesInsideAnnotations.kt")
|
||||
public void testValueClassesInsideAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -33418,6 +33418,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithForbiddenUnderlyingTypeMultiField.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithUniversal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassWithGenericUnderlyingTypeNoFeature.kt")
|
||||
public void testValueClassWithGenericUnderlyingTypeNoFeature() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithGenericUnderlyingTypeNoFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassesInsideAnnotations.kt")
|
||||
public void testValueClassesInsideAnnotations() throws Exception {
|
||||
|
||||
+6
@@ -33418,6 +33418,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithForbiddenUnderlyingTypeMultiField.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithUniversal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassWithGenericUnderlyingTypeNoFeature.kt")
|
||||
public void testValueClassWithGenericUnderlyingTypeNoFeature() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithGenericUnderlyingTypeNoFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassesInsideAnnotations.kt")
|
||||
public void testValueClassesInsideAnnotations() throws Exception {
|
||||
|
||||
+19
-14
@@ -164,20 +164,25 @@ object FirInlineClassDeclarationChecker : FirRegularClassChecker() {
|
||||
context
|
||||
)
|
||||
|
||||
!context.languageVersionSettings.supportsFeature(LanguageFeature.GenericInlineClassParameter) &&
|
||||
primaryConstructorParameter.returnTypeRef.coneType.let {
|
||||
it is ConeTypeParameterType || it.isGenericArrayOfTypeParameter()
|
||||
} -> {
|
||||
reporter.reportOn(
|
||||
primaryConstructorParameter.returnTypeRef.source,
|
||||
FirErrors.UNSUPPORTED_FEATURE,
|
||||
LanguageFeature.GenericInlineClassParameter to context.languageVersionSettings,
|
||||
context
|
||||
)
|
||||
}
|
||||
|
||||
primaryConstructorParameter.returnTypeRef.isInapplicableParameterType() -> {
|
||||
val inlineClassHasGenericUnderlyingType = primaryConstructorParameter.returnTypeRef.coneType.let {
|
||||
(it is ConeTypeParameterType || it.isGenericArrayOfTypeParameter())
|
||||
}
|
||||
if (!(context.languageVersionSettings.supportsFeature(LanguageFeature.GenericInlineClassParameter) &&
|
||||
inlineClassHasGenericUnderlyingType)
|
||||
) {
|
||||
reporter.reportOn(
|
||||
primaryConstructorParameter.returnTypeRef.source,
|
||||
FirErrors.VALUE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE,
|
||||
primaryConstructorParameter.returnTypeRef.coneType,
|
||||
context
|
||||
)
|
||||
}
|
||||
reporter.reportOn(
|
||||
primaryConstructorParameter.returnTypeRef.source,
|
||||
FirErrors.VALUE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE,
|
||||
primaryConstructorParameter.returnTypeRef.coneType,
|
||||
context
|
||||
)
|
||||
}
|
||||
|
||||
primaryConstructorParameter.returnTypeRef.coneType.isRecursiveInlineClassType(context.session) -> {
|
||||
@@ -202,7 +207,7 @@ object FirInlineClassDeclarationChecker : FirRegularClassChecker() {
|
||||
}
|
||||
|
||||
private fun FirTypeRef.isInapplicableParameterType() =
|
||||
isUnit || isNothing || coneType is ConeTypeParameterType || coneType.isGenericArrayOfTypeParameter()
|
||||
isUnit || isNothing
|
||||
|
||||
private fun ConeKotlinType.isGenericArrayOfTypeParameter(): Boolean {
|
||||
if (this.typeArguments.firstOrNull() is ConeStarProjection || !isPotentiallyArray())
|
||||
|
||||
+14
-4
@@ -103,10 +103,20 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
|
||||
val baseParameterTypeReference = baseParameter.typeReference
|
||||
if (baseParameterType != null && baseParameterTypeReference != null) {
|
||||
if (baseParameterType.isInapplicableParameterType() &&
|
||||
!(context.languageVersionSettings.supportsFeature(LanguageFeature.GenericInlineClassParameter) &&
|
||||
(baseParameterType.isTypeParameter() || baseParameterType.isGenericArrayOfTypeParameter()))
|
||||
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.GenericInlineClassParameter) &&
|
||||
(baseParameterType.isTypeParameter() || baseParameterType.isGenericArrayOfTypeParameter())
|
||||
) {
|
||||
trace.report(
|
||||
Errors.UNSUPPORTED_FEATURE.on(
|
||||
baseParameterTypeReference,
|
||||
LanguageFeature.GenericInlineClassParameter to context.languageVersionSettings
|
||||
)
|
||||
)
|
||||
baseParametersOk = false
|
||||
continue
|
||||
}
|
||||
|
||||
if (baseParameterType.isInapplicableParameterType()) {
|
||||
trace.report(Errors.VALUE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE.on(baseParameterTypeReference, baseParameterType))
|
||||
baseParametersOk = false
|
||||
continue
|
||||
@@ -154,7 +164,7 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
private fun KotlinType.isInapplicableParameterType() =
|
||||
isUnit() || isNothing() || isTypeParameter() || isGenericArrayOfTypeParameter()
|
||||
isUnit() || isNothing()
|
||||
|
||||
private fun KotlinType.isGenericArrayOfTypeParameter(): Boolean {
|
||||
if (!KotlinBuiltIns.isArray(this)) return false
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
// !SKIP_JAVAC
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
package kotlin.jvm
|
||||
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
package
|
||||
|
||||
package kotlin {
|
||||
|
||||
package kotlin.jvm {
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class Bar {
|
||||
public constructor Bar(/*0*/ u: kotlin.Unit)
|
||||
public final val u: kotlin.Unit
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class BarNullable {
|
||||
public constructor BarNullable(/*0*/ u: kotlin.Unit?)
|
||||
public final val u: kotlin.Unit?
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class Baz {
|
||||
public constructor Baz(/*0*/ u: kotlin.Nothing)
|
||||
public final val u: kotlin.Nothing
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class BazNullable {
|
||||
public constructor BazNullable(/*0*/ u: kotlin.Nothing?)
|
||||
public final val u: kotlin.Nothing?
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class Foo</*0*/ T> {
|
||||
public constructor Foo</*0*/ T>(/*0*/ x: T)
|
||||
public final val x: T
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class FooGenericArray</*0*/ T> {
|
||||
public constructor FooGenericArray</*0*/ T>(/*0*/ x: kotlin.Array<T>)
|
||||
public final val x: kotlin.Array<T>
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class FooGenericArray2</*0*/ T> {
|
||||
public constructor FooGenericArray2</*0*/ T>(/*0*/ x: kotlin.Array<kotlin.Array<T>>)
|
||||
public final val x: kotlin.Array<kotlin.Array<T>>
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class FooNullable</*0*/ T> {
|
||||
public constructor FooNullable</*0*/ T>(/*0*/ x: T?)
|
||||
public final val x: T?
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class FooStarProjectedArray {
|
||||
public constructor FooStarProjectedArray(/*0*/ x: kotlin.Array<*>)
|
||||
public final val x: kotlin.Array<*>
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.jvm.JvmInline public final value class FooStarProjectedArray2 {
|
||||
public constructor FooStarProjectedArray2(/*0*/ x: kotlin.Array<kotlin.Array<*>>)
|
||||
public final val x: kotlin.Array<kotlin.Array<*>>
|
||||
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
|
||||
}
|
||||
|
||||
public final annotation class JvmInline : kotlin.Annotation {
|
||||
public constructor JvmInline()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// FIR_IDENTICAL
|
||||
// !SKIP_JAVAC
|
||||
// SKIP_TXT
|
||||
// !LANGUAGE: +InlineClasses, -GenericInlineClassParameter
|
||||
|
||||
package kotlin.jvm
|
||||
|
||||
annotation class JvmInline
|
||||
|
||||
@JvmInline
|
||||
value class Foo<T>(val x: <!UNSUPPORTED_FEATURE!>T<!>)
|
||||
@JvmInline
|
||||
value class FooNullable<T>(val x: <!UNSUPPORTED_FEATURE!>T?<!>)
|
||||
|
||||
@JvmInline
|
||||
value class FooGenericArray<T>(val x: <!UNSUPPORTED_FEATURE!>Array<T><!>)
|
||||
@JvmInline
|
||||
value class FooGenericArray2<T>(val x: <!UNSUPPORTED_FEATURE!>Array<Array<T>><!>)
|
||||
|
||||
|
||||
Generated
+6
@@ -33508,6 +33508,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithForbiddenUnderlyingTypeMultiField.kt", TransformersFunctions.getReplaceOptionalJvmInlineAnnotationWithUniversal());
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassWithGenericUnderlyingTypeNoFeature.kt")
|
||||
public void testValueClassWithGenericUnderlyingTypeNoFeature() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/valueClasses/valueClassWithGenericUnderlyingTypeNoFeature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClassesInsideAnnotations.kt")
|
||||
public void testValueClassesInsideAnnotations() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user