From a696132dfa2748aa6d5c35e05440d14b5fe7b844 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Thu, 18 Apr 2024 12:30:14 -0700 Subject: [PATCH] Fix non-nullable type w/ ? warnings --- .../pig/generator/kotlin/KTypeDomainConverter.kt | 11 ++++++++++- .../org/partiql/pig/templates/kotlin-domain.ftl | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pig/src/main/kotlin/org/partiql/pig/generator/kotlin/KTypeDomainConverter.kt b/pig/src/main/kotlin/org/partiql/pig/generator/kotlin/KTypeDomainConverter.kt index 2cc962f..0364f90 100644 --- a/pig/src/main/kotlin/org/partiql/pig/generator/kotlin/KTypeDomainConverter.kt +++ b/pig/src/main/kotlin/org/partiql/pig/generator/kotlin/KTypeDomainConverter.kt @@ -241,7 +241,16 @@ private class KTypeDomainConverter( val elementIsKotlinPrimitive = isKotlinPrimitive(element) val elementKotlinName = element.identifier.snakeToCamelCase() when (element.typeReference.arity) { - is Arity.Required, Arity.Optional -> { + is Arity.Required -> { + KConstructorArgument( + kotlinName = elementKotlinName, + value = elementKotlinName + when { + elementIsKotlinPrimitive && useKotlinPrimitives -> ".asPrimitive()" + else -> "" + } + ) + } + is Arity.Optional -> { KConstructorArgument( kotlinName = elementKotlinName, value = elementKotlinName + when { diff --git a/pig/src/main/resources/org/partiql/pig/templates/kotlin-domain.ftl b/pig/src/main/resources/org/partiql/pig/templates/kotlin-domain.ftl index f659147..ae0a369 100644 --- a/pig/src/main/resources/org/partiql/pig/templates/kotlin-domain.ftl +++ b/pig/src/main/resources/org/partiql/pig/templates/kotlin-domain.ftl @@ -58,7 +58,11 @@ class ${t.kotlinName}( [#if p.variadic] if(${p.kotlinName}.any()) { ionSexpOf(ionSymbol("${p.tag}"), *${p.kotlinName}.map { it.toIonElement() }.toTypedArray()) } else { null }[#sep],[/#sep] [#else] + [#if p.nullable] ${p.kotlinName}?.let { ionSexpOf(ionSymbol("${p.tag}"), it.toIonElement()) }[#sep],[/#sep] + [#else] + ionSexpOf(ionSymbol("${p.tag}"), ${p.kotlinName}.toIonElement())[#sep],[/#sep] + [/#if] [/#if] [/#list] )