Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-nullable type w/ ? warnings #155

Merged
merged 1 commit into from
Apr 18, 2024
Merged

Conversation

alancai98
Copy link
Member

Issue #, if available: fixes #154

Description of changes: PIG-generated code was previously always adding a ? to non-nullable values for builder function constructor and .toIonElement calls in which there was a variadic list of parameters. This is currently a warning in Kotlin 1.6 but causes in error in Kotlin 1.7 and later.

Example for builder function constructor:

        /**
         * Creates an instance of [PartiqlBasic.Expr.Call].
         */
        fun call(
            name: String,
            args0: Expr,
            vararg args: Expr,
            metas: MetaContainer = emptyMetaContainer()
        ): PartiqlBasic.Expr.Call =
            PartiqlBasic.Expr.Call(
                name = name?.asPrimitive(),   <- `name` is not nullable
                args = listOf(args0) + args.toList(),
                metas = newMetaContainer() + metas
            )

With the fix, this will now be:

        /**
         * Creates an instance of [PartiqlBasic.Expr.Call].
         */
        fun call(
            name: String,
            args0: Expr,
            vararg args: Expr,
            metas: MetaContainer = emptyMetaContainer()
        ): PartiqlBasic.Expr.Call =
            PartiqlBasic.Expr.Call(
                name = name.asPrimitive(),
                args = listOf(args0) + args.toList(),
                metas = newMetaContainer() + metas
            )

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alancai98 alancai98 self-assigned this Apr 18, 2024
@alancai98 alancai98 requested a review from dlurton April 18, 2024 19:34
@@ -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 -> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes the builder function call

@@ -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]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes the .toIonElement() call

@alancai98 alancai98 changed the title Fix non-nullable type w/ ? warnings Fix non-nullable type w/ ? warnings Apr 18, 2024
Copy link
Member

@dlurton dlurton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alancai98 alancai98 merged commit 02f350f into main Apr 18, 2024
3 checks passed
@alancai98 alancai98 deleted the fix-nullable-warnings branch April 18, 2024 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated code doesn't compile in Kotlin 1.7 and later
3 participants