[K2]: Support java-kotlin interop for @SubclassOptInRequired
Previously, if the parent class was in Java code and the subclass in Kotlin, the opt-in usage error would not be reported for the subclass. The problem was that the extractClassFromArgument function couldn't get the class type from Java code. It was looking for a ConeClassLikeType, but found a ConeFlexibleType instead. #KT-60258 Fixed
This commit is contained in:
committed by
Space Team
parent
9fafbc1b07
commit
8156c91c47
+6
@@ -42259,6 +42259,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InnerClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaKotlinInterop.kt")
|
||||
public void testJavaKotlinInterop() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
+6
@@ -42259,6 +42259,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InnerClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaKotlinInterop.kt")
|
||||
public void testJavaKotlinInterop() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
+6
@@ -39973,6 +39973,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InnerClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaKotlinInterop.kt")
|
||||
public void testJavaKotlinInterop() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
+6
@@ -40093,6 +40093,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InnerClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaKotlinInterop.kt")
|
||||
public void testJavaKotlinInterop() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
+6
-4
@@ -93,10 +93,12 @@ fun FirExpression.extractClassFromArgument(session: FirSession): FirRegularClass
|
||||
return when (val argument = argument) {
|
||||
is FirResolvedQualifier ->
|
||||
argument.symbol as? FirRegularClassSymbol
|
||||
is FirClassReferenceExpression ->
|
||||
argument.classTypeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session)?.toRegularClassSymbol(session)
|
||||
else ->
|
||||
null
|
||||
is FirClassReferenceExpression -> {
|
||||
val classTypeRef = argument.classTypeRef
|
||||
val coneType = classTypeRef.coneType.unwrapFlexibleAndDefinitelyNotNull()
|
||||
coneType.fullyExpandedType(session).toRegularClassSymbol(session)
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// FILE: one.java
|
||||
package pcg;
|
||||
|
||||
import kotlin.ExperimentalMultiplatform;
|
||||
import kotlin.SubclassOptInRequired;
|
||||
@SubclassOptInRequired(markerClass = ExperimentalMultiplatform.class) public class Foo{}
|
||||
|
||||
// FILE: two.kt
|
||||
|
||||
import pcg.Foo
|
||||
|
||||
class Bar() : <!OPT_IN_USAGE_ERROR!>Foo<!>()
|
||||
|
||||
compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// FILE: one.java
|
||||
package pcg;
|
||||
|
||||
import kotlin.ExperimentalMultiplatform;
|
||||
import kotlin.SubclassOptInRequired;
|
||||
@SubclassOptInRequired(markerClass = ExperimentalMultiplatform.class) public class Foo{}
|
||||
|
||||
// FILE: two.kt
|
||||
|
||||
import pcg.Foo
|
||||
|
||||
class Bar() : Foo()
|
||||
|
||||
|
||||
Generated
+6
@@ -42259,6 +42259,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InnerClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("JavaKotlinInterop.kt")
|
||||
public void testJavaKotlinInterop() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("NestedClasses.kt")
|
||||
public void testNestedClasses() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user