apple/pkl · error · KotlinCodeGeneratorException
Pkl ` ` types are not supported by the Kotlin code…
Error message
Pkl `${this}` types are not supported by the Kotlin code generator. What it means
toKotlinPoetName has no Kotlin mapping for certain singleton Pkl types (PType.MODULE and PType.THIS, i.e. self types). Any property typed `module` or `this` triggers this KotlinCodeGeneratorException.
Solutions
- Re-type the property to a concrete class name instead of `this` or `module`.
- Use an explicit parent class type: `owner: Directory` rather than `owner: this`.
- Hand-write the Kotlin binding for the affected class instead of generating it.
Example fix
// before (Pkl)
class Node { parent: this }
// after
class Node { parent: Node } Defensive patterns
Strategy: validation
Validate before calling
fun usesSelfOrModuleType(t: PType?): Boolean = t == PType.MODULE || t == PType.THIS || (t is PType.Class && /* recurse members */ false) // reject before codegen if found
Type guard
fun isCodegenSafeType(t: PType?): Boolean = t != PType.MODULE && t != PType.THIS
Try / catch
try {
generator.generate(module)
} catch (e: KotlinCodeGeneratorException) {
if (e.message?.contains("types are not supported by the Kotlin code generator") == true) {
logger.error("Replace module/this self types: ${e.message}")
} else throw e
} Prevention
- Avoid `this` and `module` as property types in generated modules
- Use concrete class names for parent/owner references
- Document self-type limitation for schema authors
When it happens
Trigger: A generated module declares a property typed `module` or `this` (self type), e.g. `owner: this` or recursive `class Foo<T extends Foo<T>>` patterns.
Common situations: Modeling parent/child relationships with self-referencing types in Pkl, then generating Kotlin bindings.
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
- Pkl function types are not supported by the Kotlin code…
- Pkl union types are not supported by the Kotlin code…
- Cannot generate Kotlin code for a Pkl standard library…
- 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/12788504da6a5bc4.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt:655
}
// 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 -> NOTHING
PType.MODULE,
PType.THIS ->
// TODO: support self types: `class Foo<T extends Foo<T>>`
throw KotlinCodeGeneratorException(
"Pkl `${this}` types are not supported by the Kotlin code generator."
)
is PType.StringLiteral -> STRING
is PType.Class -> {
// if in doubt, spell it out
when (val classInfo = pClass.info) {
PClassInfo.Any -> ANY_NULL
PClassInfo.Typed,
PClassInfo.Dynamic -> ANY
PClassInfo.Boolean -> BOOLEAN
PClassInfo.String -> STRING
// seems more useful to generate `Double` than `kotlin.Number`
PClassInfo.Number -> DOUBLE
PClassInfo.Int -> LONG
PClassInfo.Float -> DOUBLE
PClassInfo.Duration -> DURATION
PClassInfo.DataSize -> DATA_SIZE
PClassInfo.Bytes -> BYTE_ARRAYView on GitHub (pinned to f3efcbfc9b)