FIR2IR: collect annotations when expanding type aliases

This commit is contained in:
pyos
2021-02-05 13:48:26 +01:00
committed by Mikhail Glukhikh
parent 872effc21e
commit d96921e287
11 changed files with 65 additions and 10 deletions
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
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.references.FirReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
@@ -86,16 +87,17 @@ class ConversionTypeContext internal constructor(
fun FirClassifierSymbol<*>.toSymbol(
session: FirSession,
classifierStorage: Fir2IrClassifierStorage,
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
handleAnnotations: ((List<FirAnnotationCall>) -> Unit)? = null
): IrClassifierSymbol {
return when (this) {
is FirTypeParameterSymbol -> {
classifierStorage.getIrTypeParameterSymbol(this, typeContext)
}
is FirTypeAliasSymbol -> {
val typeAlias = fir
val coneClassLikeType = typeAlias.expandedTypeRef.coneType as ConeClassLikeType
coneClassLikeType.lookupTag.toSymbol(session)!!.toSymbol(session, classifierStorage)
handleAnnotations?.invoke(fir.expandedTypeRef.annotations)
val coneClassLikeType = fir.expandedTypeRef.coneType as ConeClassLikeType
coneClassLikeType.lookupTag.toSymbol(session)!!.toSymbol(session, classifierStorage, typeContext, handleAnnotations)
}
is FirClassSymbol -> {
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.toSymbol
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.impl.*
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.IrStarProjectionImpl
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.types.Variance
@@ -84,13 +86,13 @@ class Fir2IrTypeConverter(
return when (this) {
is ConeKotlinErrorType -> createErrorType()
is ConeLookupTagBasedType -> {
val classId = this.classId
val irSymbol = getBuiltInClassSymbol(classId) ?: run {
val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType()
firSymbol.toSymbol(session, classifierStorage, typeContext)
}
val typeAnnotations: MutableList<IrConstructorCall> = mutableListOf()
val typeAnnotations = mutableListOf<IrConstructorCall>()
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) {
builtIns.enhancedNullabilityAnnotationConstructorCall()?.let {
typeAnnotations += it
@@ -38772,6 +38772,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
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
@TestMetadata("genericTypeAliasConstructor.kt")
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 }
}
@@ -38978,6 +38978,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
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
@TestMetadata("genericTypeAliasConstructor.kt")
public void testGenericTypeAliasConstructor() throws Exception {
@@ -38772,6 +38772,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
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
@TestMetadata("genericTypeAliasConstructor.kt")
public void testGenericTypeAliasConstructor() throws Exception {
@@ -31333,6 +31333,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
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")
public void testGenericTypeAliasConstructor() throws Exception {
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
@@ -26734,6 +26734,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
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")
public void testGenericTypeAliasConstructor() throws Exception {
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
@@ -26219,6 +26219,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
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")
public void testGenericTypeAliasConstructor() throws Exception {
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
@@ -26184,6 +26184,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
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")
public void testGenericTypeAliasConstructor() throws Exception {
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");
@@ -14490,6 +14490,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
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")
public void testGenericTypeAliasConstructor() throws Exception {
runTest("compiler/testData/codegen/box/typealias/genericTypeAliasConstructor.kt");