You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix unused variable warnings in QuerySerializerGenerator for unions with empty structs
- Add isEmptyStruct() helper to detect empty struct shapes
- Use _inner for empty structs to avoid unused variable warnings
- Use inner for non-empty structs where variable is used
- Add comprehensive tests for RestXml, AwsQuery, and RestJson protocols
- Tests enforce -D warnings via clientIntegrationTest
Copy file name to clipboardExpand all lines: codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt
+47Lines changed: 47 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,4 +44,51 @@ class AwsQueryTest {
44
44
fun`generate an aws query service that compiles`() {
45
45
clientIntegrationTest(model) { _, _ -> }
46
46
}
47
+
48
+
@Test
49
+
fun`union with empty struct generates warning-free code`() {
50
+
val modelWithEmptyStruct =
51
+
"""
52
+
namespace test
53
+
use aws.protocols#awsQuery
54
+
55
+
@awsQuery
56
+
@xmlNamespace(uri: "https://example.com/")
57
+
service TestService {
58
+
version: "2019-12-16",
59
+
operations: [TestOp]
60
+
}
61
+
62
+
operation TestOp {
63
+
input: TestInput,
64
+
output: TestOutput
65
+
}
66
+
67
+
structure TestInput {
68
+
testUnion: TestUnion
69
+
}
70
+
71
+
structure TestOutput {
72
+
testUnion: TestUnion
73
+
}
74
+
75
+
union TestUnion {
76
+
// Empty struct - should generate _inner to avoid unused variable warning
77
+
emptyStruct: EmptyStruct,
78
+
79
+
// Normal struct - should generate inner (without underscore)
80
+
normalStruct: NormalStruct
81
+
}
82
+
83
+
structure EmptyStruct {}
84
+
85
+
structure NormalStruct {
86
+
value: String
87
+
}
88
+
""".asSmithyModel()
89
+
90
+
// This test will fail with unused variable warnings if the fix is not applied
91
+
// clientIntegrationTest enforces -D warnings via codegenIntegrationTest
Copy file name to clipboardExpand all lines: codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt
+51Lines changed: 51 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -45,4 +45,55 @@ internal class RestJsonTest {
45
45
fun`generate a rest json service that compiles`() {
46
46
clientIntegrationTest(model) { _, _ -> }
47
47
}
48
+
49
+
@Test
50
+
fun`union with empty struct always uses inner variable`() {
Copy file name to clipboardExpand all lines: codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -345,6 +345,16 @@ abstract class QuerySerializerGenerator(private val codegenContext: CodegenConte
345
345
}
346
346
}
347
347
348
+
/**
349
+
* Determines if a struct shape is empty (has no members).
350
+
* Empty structs result in unused variables in union match arms since the inner value is never referenced.
0 commit comments