FIR2IR: collect annotations when expanding type aliases
This commit is contained in:
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
|||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||||
import org.jetbrains.kotlin.fir.references.FirReference
|
import org.jetbrains.kotlin.fir.references.FirReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
@@ -86,16 +87,17 @@ class ConversionTypeContext internal constructor(
|
|||||||
fun FirClassifierSymbol<*>.toSymbol(
|
fun FirClassifierSymbol<*>.toSymbol(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
classifierStorage: Fir2IrClassifierStorage,
|
classifierStorage: Fir2IrClassifierStorage,
|
||||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||||
|
handleAnnotations: ((List<FirAnnotationCall>) -> Unit)? = null
|
||||||
): IrClassifierSymbol {
|
): IrClassifierSymbol {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is FirTypeParameterSymbol -> {
|
is FirTypeParameterSymbol -> {
|
||||||
classifierStorage.getIrTypeParameterSymbol(this, typeContext)
|
classifierStorage.getIrTypeParameterSymbol(this, typeContext)
|
||||||
}
|
}
|
||||||
is FirTypeAliasSymbol -> {
|
is FirTypeAliasSymbol -> {
|
||||||
val typeAlias = fir
|
handleAnnotations?.invoke(fir.expandedTypeRef.annotations)
|
||||||
val coneClassLikeType = typeAlias.expandedTypeRef.coneType as ConeClassLikeType
|
val coneClassLikeType = fir.expandedTypeRef.coneType as ConeClassLikeType
|
||||||
coneClassLikeType.lookupTag.toSymbol(session)!!.toSymbol(session, classifierStorage)
|
coneClassLikeType.lookupTag.toSymbol(session)!!.toSymbol(session, classifierStorage, typeContext, handleAnnotations)
|
||||||
}
|
}
|
||||||
is FirClassSymbol -> {
|
is FirClassSymbol -> {
|
||||||
classifierStorage.getIrClassSymbol(this)
|
classifierStorage.getIrClassSymbol(this)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.expressions.classId
|
|||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.*
|
import org.jetbrains.kotlin.fir.types.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
|||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
@@ -84,13 +86,13 @@ class Fir2IrTypeConverter(
|
|||||||
return when (this) {
|
return when (this) {
|
||||||
is ConeKotlinErrorType -> createErrorType()
|
is ConeKotlinErrorType -> createErrorType()
|
||||||
is ConeLookupTagBasedType -> {
|
is ConeLookupTagBasedType -> {
|
||||||
val classId = this.classId
|
val typeAnnotations = mutableListOf<IrConstructorCall>()
|
||||||
val irSymbol = getBuiltInClassSymbol(classId) ?: run {
|
|
||||||
val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType()
|
|
||||||
firSymbol.toSymbol(session, classifierStorage, typeContext)
|
|
||||||
}
|
|
||||||
val typeAnnotations: MutableList<IrConstructorCall> = mutableListOf()
|
|
||||||
typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() }
|
typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() }
|
||||||
|
val irSymbol = getBuiltInClassSymbol(classId)
|
||||||
|
?: lookupTag.toSymbol(session)?.toSymbol(session, classifierStorage, typeContext) {
|
||||||
|
typeAnnotations += with(annotationGenerator) { it.toIrAnnotations() }
|
||||||
|
}
|
||||||
|
?: return createErrorType()
|
||||||
if (hasEnhancedNullability) {
|
if (hasEnhancedNullability) {
|
||||||
builtIns.enhancedNullabilityAnnotationConstructorCall()?.let {
|
builtIns.enhancedNullabilityAnnotationConstructorCall()?.let {
|
||||||
typeAnnotations += it
|
typeAnnotations += it
|
||||||
|
|||||||
+6
@@ -38772,6 +38772,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
typealias F<T, R> = T.() -> R
|
||||||
|
|
||||||
|
inline fun <T, R> T.myRun(f: F<T, R>) = f()
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val x = "K"
|
||||||
|
return "O".myRun { this + x }
|
||||||
|
}
|
||||||
+6
@@ -38978,6 +38978,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
|
|||||||
+6
@@ -38772,6 +38772,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
|
|||||||
+5
@@ -31333,6 +31333,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -26734,6 +26734,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
||||||
|
|||||||
Generated
+5
@@ -26219,6 +26219,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
||||||
|
|||||||
Generated
+5
@@ -26184,6 +26184,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -14490,6 +14490,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
runTest("compiler/testData/codegen/box/typealias/enumEntryQualifier.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionFunction.kt")
|
||||||
|
public void testExtensionFunction() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/typealias/extensionFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericTypeAliasConstructor.kt")
|
@TestMetadata("genericTypeAliasConstructor.kt")
|
||||||
public void testGenericTypeAliasConstructor() throws Exception {
|
public void testGenericTypeAliasConstructor() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user