Skip to content

Conversation

ianbotsf
Copy link
Contributor

Issue #

(none)

Description of changes

Presently, a structure member which shares a name with a top-level package cannot be codegenerated by smithy-kotlin. For example, if a structure Foo has a member aws and the service's fully-qualified package starts with aws. the following code will be generated (heavily trimmed):

class Foo {
    val aws: Type? = ...
    val otherMember: Type? = ...

    class Builder {
        var aws: Type? = null
        var otherMember: Type? = null

        // DSL builder method
        fun otherMember(block: aws.fully.qualified.package.Type.Builder.() -> Unit) {
            // This line fails to compile because `aws` resolves to the member rather than the top-level namespace.
            // The error will be something like "Unresolved reference 'fully'".
            this.otherMember = aws.fully.qualified.package.Type.invoke(block)
        }
    }
}

Unfortunately, there's no way to unambiguously refer to a package name when its shadowed inside of a statement scope. Since the conflict does not exist at the file level, this PR solves the problem by capturing references to necessary builder objects in file-local variables and invoking those in DSL builder methods instead:

// Capture an unambiguous reference to the companion object
val awsFullyQualifiedPackageTypeDslBuilderRef = aws.fully.qualified.package.Type

class Foo {
    val aws: Type? = ...
    val otherMember: Type? = ...

    class Builder {
        var aws: Type? = null
        var otherMember: Type? = null

        // DSL builder method
        fun otherMember(block: aws.fully.qualified.package.Type.Builder.() -> Unit) {
            // Invoke DSL via the previously captured ref
            this.otherMember = awsFullyQualifiedPackageTypeDslBuilderRef(block)
        }
    }
}

I don't love this and I'm open to alternative approaches.

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

@ianbotsf ianbotsf requested a review from a team as a code owner October 16, 2025 21:45

This comment has been minimized.

Copy link

Affected Artifacts

No artifacts changed size

@ianbotsf ianbotsf merged commit eaa4518 into main Oct 17, 2025
24 checks passed
@ianbotsf ianbotsf deleted the fix-member-vs-package-collision branch October 17, 2025 15:28
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.

2 participants