Skip to content

Codegen doesn't properly handle unions with a member that has the same name as the union #1129

@ianbotsf

Description

@ianbotsf

Describe the bug

Given a model:

union Foo {
    foo: Boolean
}

The generated union code does not take into account the shadowed name:

public sealed class Foo {
    public data class Foo(val value: Boolean)

    public fun asFoo(): Boolean = (this as Foo.Foo).value // Compilation error: `Foo` (the data class) has no member `Foo`
}

The problem is likely in UnionGenerator's handling of symbols.

Expected behavior

Code should be generated correctly for a union that has a member of the same name

Current behavior

Code is generated incorrectly and fails to compile

Steps to Reproduce

See above model

Possible Solution

No response

Context

No response

Smithy-Kotlin version

1.2.18

Platform (JVM/JS/Native)

JVM

Operating system and version

(n/a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions