[FE] Prohibit explicit @ContextFunctionTypeParams usage

This commit is contained in:
Anastasiya Shadrina
2021-09-19 18:12:06 +07:00
committed by TeamCityServer
parent a091b345a0
commit b3591e77be
10 changed files with 78 additions and 1 deletions
@@ -10582,6 +10582,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsage.kt")
public void testContextReceiverTypeParamsUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsage.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsageError.kt")
public void testContextReceiverTypeParamsUsageError() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsageError.kt");
}
@Test
@TestMetadata("functionalType.kt")
public void testFunctionalType() throws Exception {
@@ -10582,6 +10582,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsage.kt")
public void testContextReceiverTypeParamsUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsage.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsageError.kt")
public void testContextReceiverTypeParamsUsageError() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsageError.kt");
}
@Test
@TestMetadata("functionalType.kt")
public void testFunctionalType() throws Exception {
@@ -10582,6 +10582,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsage.kt")
public void testContextReceiverTypeParamsUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsage.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsageError.kt")
public void testContextReceiverTypeParamsUsageError() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsageError.kt");
}
@Test
@TestMetadata("functionalType.kt")
public void testFunctionalType() throws Exception {
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getAnnotationEntries
@@ -224,6 +225,12 @@ class AnnotationChecker(
*/
descriptor.forceResolveAllContents()
}
val contextReceiversSupported = languageVersionSettings.supportsFeature(ContextReceivers)
if (descriptor.fqName == FqName("kotlin.ContextFunctionTypeParams") && !contextReceiversSupported) {
trace.report(Errors.UNSUPPORTED_FEATURE.on(entry, ContextReceivers to languageVersionSettings))
}
val classDescriptor = descriptor.annotationClass ?: continue
val useSiteTarget = entry.useSiteTarget?.getAnnotationUseSiteTarget() ?: annotated.getDefaultUseSiteTarget(descriptor)
@@ -0,0 +1,8 @@
// !LANGUAGE: +ContextReceivers
// FIR_IDENTICAL
fun <T> f(t: @ContextFunctionTypeParams(42) T, tt: @ContextFunctionTypeParams(1) Int) {}
fun test() {
val f: @ContextFunctionTypeParams(1) @ExtensionFunctionType (Int, String) -> Unit = {}
}
@@ -0,0 +1,4 @@
package
public fun </*0*/ T> f(/*0*/ t: @kotlin.ContextFunctionTypeParams(count = 42) T, /*1*/ tt: @kotlin.ContextFunctionTypeParams(count = 1) kotlin.Int): kotlin.Unit
public fun test(): kotlin.Unit
@@ -0,0 +1,7 @@
// FIR_IDENTICAL
fun <T> f(t: <!UNSUPPORTED_FEATURE!>@ContextFunctionTypeParams(42)<!> T, tt: <!UNSUPPORTED_FEATURE!>@ContextFunctionTypeParams(1)<!> Int) {}
fun test() {
val f: <!UNSUPPORTED_FEATURE!>@ContextFunctionTypeParams(1)<!> @ExtensionFunctionType (Int, String) -> Unit = {}
}
@@ -0,0 +1,4 @@
package
public fun </*0*/ T> f(/*0*/ t: @kotlin.ContextFunctionTypeParams(count = 42) T, /*1*/ tt: @kotlin.ContextFunctionTypeParams(count = 1) kotlin.Int): kotlin.Unit
public fun test(): kotlin.Unit
@@ -10588,6 +10588,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsage.kt")
public void testContextReceiverTypeParamsUsage() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsage.kt");
}
@Test
@TestMetadata("contextReceiverTypeParamsUsageError.kt")
public void testContextReceiverTypeParamsUsageError() throws Exception {
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/contextReceiverTypeParamsUsageError.kt");
}
@Test
@TestMetadata("functionalType.kt")
public void testFunctionalType() throws Exception {
-1
View File
@@ -97,7 +97,6 @@ public enum class DeprecationLevel {
@MustBeDocumented
public annotation class ExtensionFunctionType
// TODO: How to make it require opt-in? @RequiresOptIn doesn't support TYPE target
@Target(TYPE)
@MustBeDocumented
public annotation class ContextFunctionTypeParams(val count: Int)