{"record":{"id":"12788504da6a5bc4","repo":"apple/pkl","slug":"pkl-this-types-are-not-supported-by-the-kotli","errorCode":null,"errorMessage":"Pkl `${this}` types are not supported by the Kotlin code generator.","messagePattern":"Pkl `(.+?)` types are not supported by the Kotlin code generator\\.","errorType":"exception","errorClass":"KotlinCodeGeneratorException","httpStatus":null,"severity":"error","filePath":"pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt","lineNumber":655,"sourceCode":"        }\n        // Kotlin type generated for [this] is a nested enum class\n        ClassName(packageName, moduleTypeName, simpleName)\n      }\n      else -> {\n        // Kotlin type generated for [this] is a top-level type alias\n        ClassName(packageName, simpleName)\n      }\n    }\n  }\n\n  private fun PType.toKotlinPoetName(): TypeName =\n    when (this) {\n      PType.UNKNOWN -> ANY_NULL\n      PType.NOTHING -> NOTHING\n      PType.MODULE,\n      PType.THIS ->\n        // TODO: support self types: `class Foo<T extends Foo<T>>`\n        throw KotlinCodeGeneratorException(\n          \"Pkl `${this}` types are not supported by the Kotlin code generator.\"\n        )\n      is PType.StringLiteral -> STRING\n      is PType.Class -> {\n        // if in doubt, spell it out\n        when (val classInfo = pClass.info) {\n          PClassInfo.Any -> ANY_NULL\n          PClassInfo.Typed,\n          PClassInfo.Dynamic -> ANY\n          PClassInfo.Boolean -> BOOLEAN\n          PClassInfo.String -> STRING\n          // seems more useful to generate `Double` than `kotlin.Number`\n          PClassInfo.Number -> DOUBLE\n          PClassInfo.Int -> LONG\n          PClassInfo.Float -> DOUBLE\n          PClassInfo.Duration -> DURATION\n          PClassInfo.DataSize -> DATA_SIZE\n          PClassInfo.Bytes -> BYTE_ARRAY","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-codegen-kotlin/src/main/kotlin/org/pkl/codegen/kotlin/KotlinCodeGenerator.kt#L637-L673","documentation":"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.","triggerScenarios":"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.","commonSituations":"Modeling parent/child relationships with self-referencing types in Pkl, then generating Kotlin bindings.","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."],"exampleFix":"// before (Pkl)\nclass Node { parent: this }\n// after\nclass Node { parent: Node }","handlingStrategy":"validation","validationCode":"fun usesSelfOrModuleType(t: PType?): Boolean =\n  t == PType.MODULE || t == PType.THIS ||\n  (t is PType.Class && /* recurse members */ false)\n// reject before codegen if found","typeGuard":"fun isCodegenSafeType(t: PType?): Boolean = t != PType.MODULE && t != PType.THIS","tryCatchPattern":"try {\n  generator.generate(module)\n} catch (e: KotlinCodeGeneratorException) {\n  if (e.message?.contains(\"types are not supported by the Kotlin code generator\") == true) {\n    logger.error(\"Replace module/this self types: ${e.message}\")\n  } else throw e\n}","preventionTips":["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"],"tags":["kotlin","codegen","self-type","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}