KMP: Put "prohbit actual typealias to Nothing and Nullable" under the flag
^KT-61668 Fixed Review: https://jetbrains.team/p/kt/reviews/12062/timeline
This commit is contained in:
+12
@@ -1683,12 +1683,24 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNothing_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNothing_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType.kt")
|
||||
public void testActualTypealiasToNullableType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNullableType_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInTypealias() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/typealias"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
|
||||
|
||||
+12
@@ -1683,12 +1683,24 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNothing_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNothing_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType.kt")
|
||||
public void testActualTypealiasToNullableType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNullableType_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInTypealias() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/typealias"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
|
||||
|
||||
+10
-7
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
@@ -62,14 +63,16 @@ object FirActualTypeAliasChecker : FirTypeAliasChecker() {
|
||||
reporter.reportOn(declaration.source, FirErrors.ACTUAL_TYPE_ALIAS_WITH_COMPLEX_SUBSTITUTION, context)
|
||||
}
|
||||
|
||||
@OptIn(UnexpandedTypeCheck::class)
|
||||
// an earlier check ensures we have an ACTUAL_TYPE_ALIAS_NOT_TO_CLASS error on non-expanded type alias
|
||||
if (expandedTypeRef.isNothing) {
|
||||
reporter.reportOn(declaration.source, FirErrors.ACTUAL_TYPE_ALIAS_TO_NOTHING, context)
|
||||
}
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) {
|
||||
@OptIn(UnexpandedTypeCheck::class)
|
||||
// an earlier check ensures we have an ACTUAL_TYPE_ALIAS_NOT_TO_CLASS error on non-expanded type alias
|
||||
if (expandedTypeRef.isNothing) {
|
||||
reporter.reportOn(declaration.source, FirErrors.ACTUAL_TYPE_ALIAS_TO_NOTHING, context)
|
||||
}
|
||||
|
||||
if (expandedTypeRef.isMarkedNullable == true) {
|
||||
reporter.reportOn(declaration.source, FirErrors.ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE, context)
|
||||
if (expandedTypeRef.isMarkedNullable == true) {
|
||||
reporter.reportOn(declaration.source, FirErrors.ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,14 +191,16 @@ class DeclarationsChecker(
|
||||
return
|
||||
}
|
||||
|
||||
if (rhs.isNothing()) {
|
||||
trace.report(ACTUAL_TYPE_ALIAS_TO_NOTHING.on(declaration))
|
||||
return
|
||||
}
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) {
|
||||
if (rhs.isNothing()) {
|
||||
trace.report(ACTUAL_TYPE_ALIAS_TO_NOTHING.on(declaration))
|
||||
return
|
||||
}
|
||||
|
||||
if (rhs.isMarkedNullable) {
|
||||
trace.report(ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE.on(declaration))
|
||||
return
|
||||
if (rhs.isMarkedNullable) {
|
||||
trace.report(ACTUAL_TYPE_ALIAS_TO_NULLABLE_TYPE.on(declaration))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// LANGUAGE: -MultiplatformRestrictions
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
<!INCOMPATIBLE_MATCHING{JVM}!>expect class E01<!>
|
||||
<!INCOMPATIBLE_MATCHING{JVM}!>expect class E02<!>
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
typealias MyNothing = Nothing
|
||||
|
||||
actual typealias E01 = Nothing
|
||||
<!ACTUAL_TYPE_ALIAS_NOT_TO_CLASS!>actual typealias E02 = MyNothing<!>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// LANGUAGE: -MultiplatformRestrictions
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class E01
|
||||
expect class E02
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
typealias MyNothing = Nothing
|
||||
|
||||
actual typealias E01 = Nothing
|
||||
<!ACTUAL_TYPE_ALIAS_NOT_TO_CLASS!>actual typealias E02 = MyNothing<!>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// LANGUAGE: -MultiplatformRestrictions
|
||||
// FIR_IDENTICAL
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class E01
|
||||
expect class E02
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
typealias MyNullable = String?
|
||||
|
||||
actual typealias E01 = String?
|
||||
<!ACTUAL_TYPE_ALIAS_NOT_TO_CLASS!>actual typealias E02 = MyNullable<!>
|
||||
Generated
+12
@@ -24678,12 +24678,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNothing_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNothing_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNothing_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType.kt")
|
||||
public void testActualTypealiasToNullableType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualTypealiasToNullableType_oldLanguageVersion.kt")
|
||||
public void testActualTypealiasToNullableType_oldLanguageVersion() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/typealias/actualTypealiasToNullableType_oldLanguageVersion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInTypealias() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/typealias"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
|
||||
|
||||
Reference in New Issue
Block a user