apple/pkl · error · KotlinCodeGeneratorException
Standard library typealias
Error message
Standard library typealias `${qualifiedName}` is not supported by Kotlin code generator. If you think this is an omission, please let us know. What it means
toKotlinPoetName cannot emit a type reference for a standard library typealias whose aliased type is enum-representable, because stdlib members are not code-generated into the user's output. It throws KotlinCodeGeneratorException asking users to report the omission.
Solutions
- Replace the stdlib typealias usage in your module with your own string-literal typealias or explicit type.
- Type the property as String if any of the alias values are acceptable.
- File an issue with the pkl project asking for support of that specific stdlib typealias.
Example fix
// before (Pkl) prop: pkl.base.SomeStdlibAlias // after typealias MyAlias = "a" | "b" prop: MyAlias
Defensive patterns
Strategy: validation
Validate before calling
if (typeAlias.isStandardLibraryMember && CodeGeneratorUtils.isRepresentableAsEnum(typeAlias.aliasedType, null)) {
throw IllegalArgumentException("Stdlib typealias ${typeAlias.qualifiedName} not supported by Kotlin codegen")
} Type guard
fun isStdlibEnumAlias(t: PType.Alias): Boolean = t.isStandardLibraryMember && CodeGeneratorUtils.isRepresentableAsEnum(t.aliasedType, null)
Try / catch
try {
generator.generate(module)
} catch (e: KotlinCodeGeneratorException) {
if (e.message?.contains("Standard library typealias") == true) {
logger.warn("Re-type property locally: ${e.message}")
} else throw e
} Prevention
- Define your own string-literal typealiases instead of relying on stdlib enum-like aliases
- Check stdlib usage in modules slated for Kotlin codegen
- Track pkl-codegen-kotlin release notes for newly supported stdlib typealiases
When it happens
Trigger: A user module references a stdlib typealias (isStandardLibraryMember == true) that resolves to an enum-representable aliased type while generating Kotlin code.
Common situations: Properties typed with stdlib type aliases (e.g. hash-algorithm-like literal unions in pkl:base) appearing in modules run through `pkl codegen kotlin`.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot generate Kotlin code for a Pkl standard library…
- Standard library class
- Standard library typealias
- Cannot generate Kotlin enum class for Pkl type alias
- Cannot generate Kotlin enum class for Pkl type alias
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/b345c7c3ba0baff3.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt:633
val (packageName, moduleTypeName) = nameMapper.map(moduleName)
return if (isModuleClass) {
ClassName(packageName, moduleTypeName)
} else {
ClassName(packageName, moduleTypeName, simpleName)
}
}
private fun TypeAlias.toKotlinPoetName(): ClassName {
val (packageName, moduleTypeName) = nameMapper.map(moduleName)
return when {
aliasedType is PType.Alias -> {
// Kotlin type generated for [this] is a top-level type alias
ClassName(packageName, simpleName)
}
CodeGeneratorUtils.isRepresentableAsEnum(aliasedType, null) -> {
if (isStandardLibraryMember) {
throw KotlinCodeGeneratorException(
"Standard library typealias `${qualifiedName}` is not supported by Kotlin code generator." +
" If you think this is an omission, please let us know."
)
}
// Kotlin type generated for [this] is a nested enum class
ClassName(packageName, moduleTypeName, simpleName)
}
else -> {
// Kotlin type generated for [this] is a top-level type alias
ClassName(packageName, simpleName)
}
}
}
private fun PType.toKotlinPoetName(): TypeName =
when (this) {
PType.UNKNOWN -> ANY_NULL
PType.NOTHING -> NOTHINGView on GitHub (pinned to f3efcbfc9b)