[FIR] Fix varargs of unsigned numbers
This commit is contained in:
@@ -14,8 +14,9 @@ object StandardClassIds {
|
|||||||
private val BASE_KOTLIN_PACKAGE = FqName("kotlin")
|
private val BASE_KOTLIN_PACKAGE = FqName("kotlin")
|
||||||
private val BASE_REFLECT_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("reflect"))
|
private val BASE_REFLECT_PACKAGE = BASE_KOTLIN_PACKAGE.child(Name.identifier("reflect"))
|
||||||
private fun String.baseId() = ClassId(BASE_KOTLIN_PACKAGE, Name.identifier(this))
|
private fun String.baseId() = ClassId(BASE_KOTLIN_PACKAGE, Name.identifier(this))
|
||||||
|
private fun ClassId.unsignedId() = ClassId(BASE_KOTLIN_PACKAGE, Name.identifier("U" + shortClassName.identifier))
|
||||||
private fun String.reflectId() = ClassId(BASE_REFLECT_PACKAGE, Name.identifier(this))
|
private fun String.reflectId() = ClassId(BASE_REFLECT_PACKAGE, Name.identifier(this))
|
||||||
private fun Name.arrayId() = ClassId(Array.packageFqName, Name.identifier(identifier + Array.shortClassName.identifier))
|
private fun Name.primitiveArrayId() = ClassId(Array.packageFqName, Name.identifier(identifier + Array.shortClassName.identifier))
|
||||||
|
|
||||||
val Nothing = "Nothing".baseId()
|
val Nothing = "Nothing".baseId()
|
||||||
val Unit = "Unit".baseId()
|
val Unit = "Unit".baseId()
|
||||||
@@ -33,6 +34,11 @@ object StandardClassIds {
|
|||||||
val Float = "Float".baseId()
|
val Float = "Float".baseId()
|
||||||
val Double = "Double".baseId()
|
val Double = "Double".baseId()
|
||||||
|
|
||||||
|
val UByte = Byte.unsignedId()
|
||||||
|
val UShort = Short.unsignedId()
|
||||||
|
val UInt = Int.unsignedId()
|
||||||
|
val ULong = Long.unsignedId()
|
||||||
|
|
||||||
val String = "String".baseId()
|
val String = "String".baseId()
|
||||||
|
|
||||||
val KProperty = "KProperty".reflectId()
|
val KProperty = "KProperty".reflectId()
|
||||||
@@ -45,20 +51,19 @@ object StandardClassIds {
|
|||||||
fun byName(name: String) = name.baseId()
|
fun byName(name: String) = name.baseId()
|
||||||
fun reflectByName(name: String) = name.reflectId()
|
fun reflectByName(name: String) = name.reflectId()
|
||||||
|
|
||||||
val primitiveArrayTypeByElementType: Map<ClassId, ClassId> = mutableMapOf<ClassId, ClassId>().apply {
|
|
||||||
fun addPrimitive(id: ClassId) {
|
|
||||||
put(id, id.shortClassName.arrayId())
|
|
||||||
}
|
|
||||||
|
|
||||||
addPrimitive(Boolean)
|
val primitiveTypes = listOf(
|
||||||
addPrimitive(Char)
|
Boolean, Char,
|
||||||
addPrimitive(Byte)
|
Byte, Short, Int, Long,
|
||||||
addPrimitive(Short)
|
Float, Double
|
||||||
addPrimitive(Int)
|
)
|
||||||
addPrimitive(Long)
|
|
||||||
addPrimitive(Float)
|
|
||||||
addPrimitive(Double)
|
|
||||||
}
|
|
||||||
|
|
||||||
val elementTypeByPrimitiveArrayType = primitiveArrayTypeByElementType.map { (k, v) -> v to k }.toMap()
|
val primitiveArrayTypeByElementType = primitiveTypes.associate { id -> id to id.shortClassName.primitiveArrayId() }
|
||||||
|
val elementTypeByPrimitiveArrayType = primitiveArrayTypeByElementType.inverseMap()
|
||||||
|
|
||||||
|
val unsignedTypes = listOf(UByte, UShort, UInt, ULong)
|
||||||
|
val unsignedArrayTypeByElementType = unsignedTypes.associate { id -> id to id.shortClassName.primitiveArrayId() }
|
||||||
|
val elementTypeByUnsignedArrayType = unsignedArrayTypeByElementType.inverseMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun <K, V> Map<K, V>.inverseMap() = entries.associate { (k, v) -> v to k }
|
||||||
@@ -19,7 +19,9 @@ fun ConeTypeProjection.createArrayOf(session: FirSession, nullable: Boolean = fa
|
|||||||
if (this is ConeKotlinTypeProjection) {
|
if (this is ConeKotlinTypeProjection) {
|
||||||
val type = type.lowerBoundIfFlexible()
|
val type = type.lowerBoundIfFlexible()
|
||||||
if (type is ConeClassLikeType) {
|
if (type is ConeClassLikeType) {
|
||||||
val primitiveArrayId = StandardClassIds.primitiveArrayTypeByElementType[type.lookupTag.classId]
|
val classId = type.lookupTag.classId
|
||||||
|
val primitiveArrayId =
|
||||||
|
StandardClassIds.primitiveArrayTypeByElementType[classId] ?: StandardClassIds.unsignedArrayTypeByElementType[classId]
|
||||||
if (primitiveArrayId != null) {
|
if (primitiveArrayId != null) {
|
||||||
return primitiveArrayId.invoke(symbolProvider).constructType(emptyArray(), nullable)
|
return primitiveArrayId.invoke(symbolProvider).constructType(emptyArray(), nullable)
|
||||||
}
|
}
|
||||||
@@ -36,7 +38,7 @@ fun ConeKotlinType.arrayElementType(session: FirSession): ConeKotlinType? {
|
|||||||
val classId = type.lookupTag.classId
|
val classId = type.lookupTag.classId
|
||||||
if (classId == StandardClassIds.Array)
|
if (classId == StandardClassIds.Array)
|
||||||
return (type.typeArguments.first() as ConeKotlinTypeProjection).type
|
return (type.typeArguments.first() as ConeKotlinTypeProjection).type
|
||||||
val elementType = StandardClassIds.elementTypeByPrimitiveArrayType[classId]
|
val elementType = StandardClassIds.elementTypeByPrimitiveArrayType[classId] ?: StandardClassIds.elementTypeByUnsignedArrayType[classId]
|
||||||
if (elementType != null) {
|
if (elementType != null) {
|
||||||
return elementType.invoke(session.firSymbolProvider).constructType(emptyArray(), isNullable = false)
|
return elementType.invoke(session.firSymbolProvider).constructType(emptyArray(), isNullable = false)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -77,8 +77,8 @@ FILE fqName:<root> fileName:/signedToUnsignedConversions_test.kt
|
|||||||
FUN name:takeULong visibility:public modality:FINAL <> (u:kotlin.ULong) returnType:kotlin.Unit
|
FUN name:takeULong visibility:public modality:FINAL <> (u:kotlin.ULong) returnType:kotlin.Unit
|
||||||
VALUE_PARAMETER name:u index:0 type:kotlin.ULong
|
VALUE_PARAMETER name:u index:0 type:kotlin.ULong
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
FUN name:takeUBytes visibility:public modality:FINAL <> (u:kotlin.Array<out kotlin.UByte>) returnType:kotlin.Unit
|
FUN name:takeUBytes visibility:public modality:FINAL <> (u:kotlin.UByteArray) returnType:kotlin.Unit
|
||||||
VALUE_PARAMETER name:u index:0 type:kotlin.Array<out kotlin.UByte> varargElementType:kotlin.UByte [vararg]
|
VALUE_PARAMETER name:u index:0 type:kotlin.UByteArray varargElementType:kotlin.UByte [vararg]
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
FUN name:takeLong visibility:public modality:FINAL <> (l:kotlin.Long) returnType:kotlin.Unit
|
FUN name:takeLong visibility:public modality:FINAL <> (l:kotlin.Long) returnType:kotlin.Unit
|
||||||
VALUE_PARAMETER name:l index:0 type:kotlin.Long
|
VALUE_PARAMETER name:l index:0 type:kotlin.Long
|
||||||
|
|||||||
Reference in New Issue
Block a user