提交 d4de2c4d 编写于 作者: D Denis.Zharkov

Add check that we have JDK 15 in classpath when using @JvmRecord

^KT-43677 In Progress
上级 85962d83
......@@ -201,6 +201,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
}
@TestMetadata("jvmRecordWithoutJdk15.kt")
public void testJvmRecordWithoutJdk15() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmRecordWithoutJdk15.kt");
}
@TestMetadata("JvmSyntheticOnDelegate.kt")
public void testJvmSyntheticOnDelegate() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
......
......@@ -10,12 +10,14 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.resolveTopLevelClass
import org.jetbrains.kotlin.resolve.jvm.JAVA_LANG_RECORD_FQ_NAME
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_RECORD_ANNOTATION_FQ_NAME
import org.jetbrains.kotlin.resolve.jvm.annotations.isJvmRecord
......@@ -29,6 +31,11 @@ object JvmRecordApplicabilityChecker : DeclarationChecker {
declaration.annotationEntries.firstOrNull { it.shortName == JVM_RECORD_ANNOTATION_FQ_NAME.shortName() }
?: declaration
if (context.moduleDescriptor.resolveTopLevelClass(JAVA_LANG_RECORD_FQ_NAME, NoLookupLocation.FOR_DEFAULT_IMPORTS) == null) {
context.trace.report(ErrorsJvm.JVM_RECORD_REQUIRES_JDK15.on(reportOn))
return
}
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.JvmRecordSupport)) {
context.trace.report(
Errors.UNSUPPORTED_FEATURE.on(
......
......@@ -157,6 +157,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(JVM_RECORD_NOT_VAL_PARAMETER, "Constructor parameter of @JvmRecord class should be a val");
MAP.put(JVM_RECORD_NOT_LAST_VARARG_PARAMETER, "Only the last constructor parameter of @JvmRecord may be a vararg");
MAP.put(JVM_RECORD_EXTENDS_CLASS, "Record cannot inherit an other class but java.lang.Record" , RENDER_TYPE);
MAP.put(JVM_RECORD_REQUIRES_JDK15, "Using @JvmRecords requires at least JDK 15");
String MESSAGE_FOR_CONCURRENT_HASH_MAP_CONTAINS =
"Method 'contains' from ConcurrentHashMap may have unexpected semantics: it calls 'containsValue' instead of 'containsKey'. " +
......
......@@ -120,6 +120,7 @@ public interface ErrorsJvm {
DiagnosticFactory0<PsiElement> JVM_RECORD_NOT_VAL_PARAMETER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> JVM_RECORD_NOT_LAST_VARARG_PARAMETER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, KotlinType> JVM_RECORD_EXTENDS_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> JVM_RECORD_REQUIRES_JDK15 = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtDeclaration> NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
......
// !LANGUAGE: +JvmRecordSupport
// SKIP_TXT
@JvmRecord
class MyRec(
val x: String,
val y: Int,
vararg val z: Double,
)
// !LANGUAGE: +JvmRecordSupport
// SKIP_TXT
<!JVM_RECORD_REQUIRES_JDK15!>@JvmRecord<!>
class MyRec(
val x: String,
val y: Int,
vararg val z: Double,
)
......@@ -201,6 +201,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
}
@TestMetadata("jvmRecordWithoutJdk15.kt")
public void testJvmRecordWithoutJdk15() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmRecordWithoutJdk15.kt");
}
@TestMetadata("JvmSyntheticOnDelegate.kt")
public void testJvmSyntheticOnDelegate() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
......
......@@ -201,6 +201,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
}
@TestMetadata("jvmRecordWithoutJdk15.kt")
public void testJvmRecordWithoutJdk15() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmRecordWithoutJdk15.kt");
}
@TestMetadata("JvmSyntheticOnDelegate.kt")
public void testJvmSyntheticOnDelegate() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册