Skip to content

CBOR Implementation Fails to Box Recursive Union Variants #4115

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

Open
drganjoo opened this issue May 7, 2025 · 0 comments · May be fixed by #4116
Open

CBOR Implementation Fails to Box Recursive Union Variants #4115

drganjoo opened this issue May 7, 2025 · 0 comments · May be fixed by #4116

Comments

@drganjoo
Copy link
Contributor

drganjoo commented May 7, 2025

The CBOR implementation is not properly handling recursive data structures by failing to apply Box to union variants where required. This results in uncompilable Rust code for recursive types.

Issue Details

Using the following Smithy model with recursive type references:

@rpcv2Cbor
service SampleService {
    operations: [
        GetRelatedProduct
    ]
}

operation GetRelatedProduct {
    input := {
        product: ProductListing
    }
    output := {
        product: ProductListing
    }
}

union ProductListing {
    Related: RelatedProduct
}

structure RelatedProduct {
    name: String,
    relatedTo: ProductListing
}

Current Output

The union deserializer currently generates code without boxing the recursive type:

Ok(match decoder.str()?.as_ref() {
    "Related" => crate::types::ProductListing::Related(crate::protocol_serde::shape_related_product::de_related_product(decoder)?),
    _ => {
        decoder.skip()?;
        crate::types::ProductListing::Unknown
    }
})

Expected Output

The deserializer should box recursive variants to prevent infinite size errors:

Ok(match decoder.str()?.as_ref() {
    "Related" => crate::types::ProductListing::Related(
        Box::new(crate::protocol_serde::shape_related_product::de_related_product(decoder)?)
    ),
    _ => {
        decoder.skip()?;
        crate::types::ProductListing::Unknown
    }
})

This implementation correctly uses Box to handle the recursive relationship between ProductListing and RelatedProduct.

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 a pull request may close this issue.

1 participant