[FIR] getValueClassUnderlyingParameters: fix TODO
^KT-53573 Obsolete
This commit is contained in:
committed by
Space Team
parent
5e63f7627f
commit
1642eaa48a
+3
@@ -0,0 +1,3 @@
|
||||
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
class X(<expr>resolveMe: Int = 5</expr>)
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
KT element: KtParameter
|
||||
FIR element: FirValueParameterImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
[ResolvedTo(BODY_RESOLVE)] resolveMe: R|kotlin/Int| = Int(5)
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(IMPORTS)] constructorParameter.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(STATUS)] class X : R|kotlin/Any| {
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=X] constructor([ResolvedTo(BODY_RESOLVE)] resolveMe: R|kotlin/Int| = Int(5)): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -477,6 +477,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorParameter.kt")
|
||||
public void testConstructorParameter() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/constructorParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorProperty.kt")
|
||||
public void testConstructorProperty() throws Exception {
|
||||
|
||||
+6
@@ -477,6 +477,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorParameter.kt")
|
||||
public void testConstructorParameter() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/constructorParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorProperty.kt")
|
||||
public void testConstructorProperty() throws Exception {
|
||||
|
||||
+6
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -42,23 +42,19 @@ internal fun ConeKotlinType.unsubstitutedUnderlyingTypeForInlineClass(session: F
|
||||
|
||||
fun computeValueClassRepresentation(klass: FirRegularClass, session: FirSession): ValueClassRepresentation<ConeSimpleKotlinType>? {
|
||||
val parameters = klass.getValueClassUnderlyingParameters(session)?.takeIf { it.isNotEmpty() } ?: return null
|
||||
val fields = parameters.map { it.name to it.returnTypeRef.coneType as ConeSimpleKotlinType }
|
||||
val fields = parameters.map { it.name to it.symbol.resolvedReturnType as ConeSimpleKotlinType }
|
||||
fields.singleOrNull()?.let { (name, type) ->
|
||||
if (isRecursiveSingleFieldValueClass(type, session, mutableSetOf(type))) { // escape stack overflow
|
||||
return InlineClassRepresentation(name, type)
|
||||
}
|
||||
}
|
||||
|
||||
return createValueClassRepresentation(session.typeContext, fields)
|
||||
}
|
||||
|
||||
private fun FirRegularClass.getValueClassUnderlyingParameters(session: FirSession): List<FirValueParameter>? {
|
||||
if (!isInline) return null
|
||||
|
||||
val primaryConstructorIfAny = primaryConstructorIfAny(session) ?: return null
|
||||
// FIXME: ATM we cannot lazy-resolve value parameters individually because of KT-53573
|
||||
primaryConstructorIfAny.lazyResolveToPhase(FirResolvePhase.TYPES)
|
||||
|
||||
return primaryConstructorIfAny.fir.valueParameters
|
||||
return primaryConstructorIfAny(session)?.fir?.valueParameters
|
||||
}
|
||||
|
||||
private fun isRecursiveSingleFieldValueClass(
|
||||
@@ -74,11 +70,9 @@ private fun ConeSimpleKotlinType.valueClassRepresentationTypeMarkersList(session
|
||||
val symbol = this.toSymbol(session) as? FirRegularClassSymbol ?: return null
|
||||
if (!symbol.fir.isInline) return null
|
||||
symbol.fir.valueClassRepresentation?.let { return it.underlyingPropertyNamesToTypes }
|
||||
symbol.lazyResolveToPhase(FirResolvePhase.TYPES)
|
||||
|
||||
val constructorSymbol = symbol.fir.primaryConstructorIfAny(session) ?: return null
|
||||
return constructorSymbol.valueParameterSymbols
|
||||
.onEach { it.lazyResolveToPhase(FirResolvePhase.TYPES) }
|
||||
.map { it.name to it.resolvedReturnType as ConeSimpleKotlinType }
|
||||
return constructorSymbol.valueParameterSymbols.map { it.name to it.resolvedReturnType as ConeSimpleKotlinType }
|
||||
}
|
||||
|
||||
fun FirSimpleFunction.isTypedEqualsInValueClass(session: FirSession): Boolean =
|
||||
|
||||
Reference in New Issue
Block a user