diff --git a/CHANGELOG.md b/CHANGELOG.md index cada834fd82..cb64b8f6416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ 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) -------------------------- diff --git a/codegen-test/build.gradle.kts b/codegen-test/build.gradle.kts index f815edecacd..91909f8ca74 100644 --- a/codegen-test/build.gradle.kts +++ b/codegen-test/build.gradle.kts @@ -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() ) diff --git a/codegen-test/model/naming-obstacle-course.smithy b/codegen-test/model/naming-obstacle-course-ops.smithy similarity index 100% rename from codegen-test/model/naming-obstacle-course.smithy rename to codegen-test/model/naming-obstacle-course-ops.smithy diff --git a/codegen-test/model/naming-obstacle-course-structs.smithy b/codegen-test/model/naming-obstacle-course-structs.smithy new file mode 100644 index 00000000000..7b40c352ddb --- /dev/null +++ b/codegen-test/model/naming-obstacle-course-structs.smithy @@ -0,0 +1,53 @@ +$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 +} diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt index 000ed558e92..1337d56eea4 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/UnionGenerator.kt @@ -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") {