Check JvmRecordSupport language feature before generating synthetic properties
This commit is contained in:
+7
-1
@@ -94,7 +94,11 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor, SyntheticPropert
|
||||
}
|
||||
}
|
||||
|
||||
class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope.Default() {
|
||||
class JavaSyntheticPropertiesScope(
|
||||
storageManager: StorageManager,
|
||||
private val lookupTracker: LookupTracker,
|
||||
private val supportJavaRecords: Boolean,
|
||||
) : SyntheticScope.Default() {
|
||||
private val syntheticPropertyInClass =
|
||||
storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
|
||||
syntheticPropertyInClassNotCached(pair.first, pair.second)
|
||||
@@ -178,6 +182,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
name: Name,
|
||||
ownerClass: ClassDescriptor
|
||||
): PropertyDescriptor? {
|
||||
if (!supportJavaRecords) return null
|
||||
|
||||
val componentLikeMethod =
|
||||
ownerClass.unsubstitutedMemberScope
|
||||
.getContributedFunctions(name, NoLookupLocation.FROM_SYNTHETIC_SCOPE)
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionOracle
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.resolve.scopes.synthetic.FunInterfaceConstructorsSyntheticScope
|
||||
@@ -52,7 +52,11 @@ class JavaSyntheticScopes(
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument) &&
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.NewInference)
|
||||
|
||||
val javaSyntheticPropertiesScope = JavaSyntheticPropertiesScope(storageManager, lookupTracker)
|
||||
val javaSyntheticPropertiesScope =
|
||||
JavaSyntheticPropertiesScope(
|
||||
storageManager, lookupTracker,
|
||||
supportJavaRecords = languageVersionSettings.supportsFeature(LanguageFeature.JvmRecordSupport)
|
||||
)
|
||||
val scopesFromExtensions = SyntheticScopeProviderExtension
|
||||
.getInstances(project)
|
||||
.flatMap { it.getScopes(moduleDescriptor, javaSyntheticPropertiesScope) }
|
||||
@@ -100,4 +104,4 @@ interface SyntheticScopeProviderExtension {
|
||||
)
|
||||
|
||||
fun getScopes(moduleDescriptor: ModuleDescriptor, javaSyntheticPropertiesScope: JavaSyntheticPropertiesScope): List<SyntheticScope>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// !LANGUAGE: +JvmRecordSupport
|
||||
// JVM_TARGET: 15_PREVIEW
|
||||
// FILE: MyRec.java
|
||||
public record MyRec(String name) {}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
// !LANGUAGE: -JvmRecordSupport
|
||||
// SKIP_TXT
|
||||
// FILE: JRecord.java
|
||||
public record JRecord(int x, CharSequence y) {}
|
||||
// FILE: main.kt
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>@JvmRecord<!>
|
||||
class MyRec(
|
||||
@@ -7,3 +10,13 @@ class MyRec(
|
||||
val y: Int,
|
||||
vararg val z: Double,
|
||||
)
|
||||
|
||||
fun foo(jr: JRecord) {
|
||||
JRecord(1, "")
|
||||
|
||||
jr.x()
|
||||
jr.y()
|
||||
|
||||
jr.<!FUNCTION_CALL_EXPECTED!>x<!>
|
||||
jr.<!FUNCTION_CALL_EXPECTED!>y<!>
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// !LANGUAGE: +JvmRecordSupport
|
||||
// FILE: MyRecord.java
|
||||
public record MyRecord(int x, CharSequence y) {
|
||||
|
||||
|
||||
+5
-4
@@ -33,9 +33,10 @@ class DebuggerFieldExpressionCodegenExtension : ExpressionCodegenExtension {
|
||||
if (propertyDescriptor is JavaPropertyDescriptor) {
|
||||
val containingClass = propertyDescriptor.containingDeclaration as? JavaClassDescriptor
|
||||
if (containingClass != null) {
|
||||
val correspondingGetter = JavaSyntheticPropertiesScope(LockBasedStorageManager.NO_LOCKS, LookupTracker.DO_NOTHING)
|
||||
.getSyntheticExtensionProperties(listOf(containingClass.defaultType), NoLookupLocation.FROM_BACKEND)
|
||||
.firstOrNull { it.name == propertyDescriptor.name }
|
||||
val correspondingGetter =
|
||||
JavaSyntheticPropertiesScope(LockBasedStorageManager.NO_LOCKS, LookupTracker.DO_NOTHING, supportJavaRecords = true)
|
||||
.getSyntheticExtensionProperties(listOf(containingClass.defaultType), NoLookupLocation.FROM_BACKEND)
|
||||
.firstOrNull { it.name == propertyDescriptor.name }
|
||||
|
||||
if (correspondingGetter != null) {
|
||||
return c.codegen.intermediateValueForProperty(
|
||||
@@ -49,4 +50,4 @@ class DebuggerFieldExpressionCodegenExtension : ExpressionCodegenExtension {
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.synthetic.JavaSyntheticPropertiesScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class DebuggerFieldKotlinIndicesHelperExtension : KotlinIndicesHelperExtension {
|
||||
override fun appendExtensionCallables(
|
||||
@@ -23,7 +22,8 @@ class DebuggerFieldKotlinIndicesHelperExtension : KotlinIndicesHelperExtension {
|
||||
nameFilter: (String) -> Boolean,
|
||||
lookupLocation: LookupLocation
|
||||
) {
|
||||
val javaPropertiesScope = JavaSyntheticPropertiesScope(LockBasedStorageManager.NO_LOCKS, LookupTracker.DO_NOTHING)
|
||||
val javaPropertiesScope =
|
||||
JavaSyntheticPropertiesScope(LockBasedStorageManager.NO_LOCKS, LookupTracker.DO_NOTHING, supportJavaRecords = true)
|
||||
val fieldScope = DebuggerFieldSyntheticScope(javaPropertiesScope)
|
||||
|
||||
for (property in fieldScope.getSyntheticExtensionProperties(receiverTypes, lookupLocation)) {
|
||||
@@ -41,4 +41,4 @@ class DebuggerFieldKotlinIndicesHelperExtension : KotlinIndicesHelperExtension {
|
||||
) {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user