Zac Sweers
02/28/2025, 6:46 AMConeClassLikeType
typed with a FirFunctionTypeRef
? Essentially I'm trying to add a supertype like Factory<() -> Unit>
in a supertype generation extension, but struggling to find an API for parameterizing an FirClassLikeSymbol
with one since FirFunctionTypeRef.coneType
doesn't workZac Sweers
02/28/2025, 6:47 AMis FirFunctionTypeRef
branch to this when statement and use it in the returned parameterized factory type at the end
https://github.com/ZacSweers/metro/blob/main/compiler/src/main/kotlin/dev/zacsweers/metro/compiler/fir/generators/ProvidesFactoryFirGenerator.kt#L319dmitriy.novozhilov
02/28/2025, 7:47 AMFirFunctionTypeRef
is an unresolved functional type, you should not rely on it.
You need something like this:
fun createFunctionNType(arguments: List<ConeTypeProjection>): ConeKotlinType {
return FunctionTypeKind.Function
.numberedClassId(arguments.size - 1)
.toLookupTag()
.constructClassType(
arguments.toTypedArray(),
isMarkedNullable = false
)
}
dmitriy.novozhilov
02/28/2025, 7:48 AMKFunction
, SuspendFunction
, KSuspendFunction
in the FunctionTypeKind
if you needZac Sweers
02/28/2025, 3:42 PMarguments
coming from in this case?dmitriy.novozhilov
02/28/2025, 3:49 PMdmitriy.novozhilov
02/28/2025, 3:50 PMJacob Applin
02/28/2025, 3:57 PMoverride fun generateTopLevelClassLikeDeclaration(classId: ClassId): FirClassLikeSymbol<*> {
val functionSymbol: FirNamedFunctionSymbol = functionsToAlias().single {
it.name == classId.shortClassName
}
return buildTypeAlias {
moduleData = session.moduleData
origin = Key.origin
name = classId.shortClassName
status = functionSymbol.resolvedStatus
symbol = FirTypeAliasSymbol(classId)
expandedTypeRef = functionSymbol.valueParameterSymbols.run {
buildResolvedTypeRef {
coneType = ConeClassLikeTypeImpl(
lookupTag = StandardClassIds.FunctionN(size).toLookupTag(),
typeArguments = arrayOf(
*map { it.resolvedReturnType }.toTypedArray(),
functionSymbol.resolvedReturnType,
),
isMarkedNullable = false,
)
annotations.addAll(functionSymbol.annotations)
}
}
}.symbol
}
Zac Sweers
02/28/2025, 3:57 PMJacob Applin
02/28/2025, 3:57 PM@Composable
to the generated typeliasesdmitriy.novozhilov
02/28/2025, 4:40 PMZac Sweers
02/28/2025, 7:18 PMZac Sweers
03/01/2025, 3:46 AM