Unverified Commit 58d0da50 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Fix name collision in generated union functions (#643)

* Fix name collision in generated union functions

* Update the CHANGELOG
parent b3a5d07e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
vNext (Month Day, Year)
-----------------------

**New this week**

- (When complete) Add profile file provider for region (#594, #xyz)
- Add experimental `dvr` module to smithy-client. This will enable easier testing of HTTP traffic. (#640)
- Add profile file credential provider implementation. This implementation currently does not support credential sources
  for assume role providers other than environment variables. (#640)
- :bug: Fix name collision that occurred when a model had both a union and a structure named `Result` (#643)

v0.20 (August 10th, 2021)
--------------------------
+7 −1
Original line number Diff line number Diff line
@@ -61,7 +61,13 @@ val CodegenTests = listOf(
    ),
    CodegenTest(
        "crate#Config",
        "naming_test", """
        "naming_test_ops", """
            , "codegen": { "renameErrors": false }
        """.trimIndent()
    ),
    CodegenTest(
        "naming_obs_structs#NamingObstacleCourseStructs",
        "naming_test_structs", """
            , "codegen": { "renameErrors": false }
        """.trimIndent()
    )
+53 −0
Original line number Diff line number Diff line
$version: "1.0"
namespace naming_obs_structs

use aws.protocols#awsJson1_1
use aws.api#service

/// Confounds model generation machinery with lots of problematic names
@awsJson1_1
@service(sdkId: "NamingObstacleCourseStructs")
service NamingObstacleCourseStructs {
    version: "2006-03-01",
    operations: [
       Structs,
    ]
}

structure SomethingElse {
    result: Result,
    resultList: ResultList,
    option: Option,
    optionList: OptionList,
    someUnion: SomeUnion,
}

union SomeUnion {
    Result: Result,
    Option: Option,
}

structure Result {
    value: String,
}
list ResultList {
    member: Result,
}
structure Option {
    value: String,
}
list OptionList {
    member: Result,
}

structure StructsInputOutput {
    result: Result,
    resultList: ResultList,
    option: Option,
    optionList: OptionList,
    somethingElse: SomethingElse,
}
operation Structs {
    input: StructsInputOutput,
    output: StructsInputOutput
}
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class UnionGenerator(
                if (sortedMembers.size == 1) {
                    Attribute.Custom("allow(irrefutable_let_patterns)").render(this)
                }
                rustBlock("pub fn as_$funcNamePart(&self) -> Result<&#T, &Self>", memberSymbol) {
                rustBlock("pub fn as_$funcNamePart(&self) -> std::result::Result<&#T, &Self>", memberSymbol) {
                    rust("if let ${unionSymbol.name}::$variantName(val) = &self { Ok(&val) } else { Err(&self) }")
                }
                rustBlock("pub fn is_$funcNamePart(&self) -> bool") {