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