From 5a1b9bb5cf894b1fc0da2cb6dac1b1cc2cd664e2 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 10 Aug 2021 16:47:07 -0700 Subject: [PATCH 1/2] Fix name collision in generated union functions --- codegen-test/build.gradle.kts | 8 ++- ...ithy => naming-obstacle-course-ops.smithy} | 0 .../naming-obstacle-course-structs.smithy | 53 +++++++++++++++++++ .../smithy/generators/UnionGenerator.kt | 2 +- 4 files changed, 61 insertions(+), 2 deletions(-) rename codegen-test/model/{naming-obstacle-course.smithy => naming-obstacle-course-ops.smithy} (100%) create mode 100644 codegen-test/model/naming-obstacle-course-structs.smithy 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") { From 74c61816ebe3b965b4332bd78830eb2a8db67a07 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 10 Aug 2021 16:58:00 -0700 Subject: [PATCH 2/2] Update the CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3736ba2060b..5414a9486d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ vNext (Month Day, Year) ----------------------- + +**New This Week** - (When complete) Add profile file provider for region (#594, #xyz) +- :bug: Fix name collision that occurred when a model had both a union and a structure named `Result` (#643) v0.20 (August 10th, 2021) --------------------------