Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct unmutated/unused variable warnings when building SDK #1770

Open
jbelkins opened this issue Sep 20, 2024 · 3 comments
Open

Correct unmutated/unused variable warnings when building SDK #1770

jbelkins opened this issue Sep 20, 2024 · 3 comments
Labels
bug This issue is a bug.

Comments

@jbelkins
Copy link
Contributor

Describe the bug

When building the SDK, the following warnings are received:

/Users/jbelkins/Code/Xcode/aws-sdk-swift/Sources/Services/AWSWAFV2/Sources/AWSWAFV2/Models.swift:12427:13: warning: variable 'value' was never mutated; consider changing to 'let' constant
12425 |     static func read(from reader: SmithyJSON.Reader) throws -> WAFV2ClientTypes.NotStatement {
12426 |         guard reader.hasContent else { throw SmithyReadWrite.ReaderError.requiredValueNotPresent }
12427 |         var value = WAFV2ClientTypes.NotStatement()
      |             `- warning: variable 'value' was never mutated; consider changing to 'let' constant
12428 |         value.statement = try reader["Statement"].readIfPresent(with: WAFV2ClientTypes.Statement.read(from:))
12429 |         return value
/Users/jbelkins/Code/Xcode/aws-sdk-swift/Sources/Services/AWSQBusiness/Sources/AWSQBusiness/Models.swift:9946:39: warning: immutable value 'value' was never used; consider replacing with '_' or removing it
 9944 |                 try writer["payloadFieldNameSeparator"].write(value.payloadFieldNameSeparator, with: SmithyReadWrite.WritingClosures.writeString(value:to:))
 9945 |                 payload = try writer.data()
 9946 |             case .endofinputevent(let value):
      |                                       `- warning: immutable value 'value' was never used; consider replacing with '_' or removing it
 9947 |                 headers.append(.init(name: ":event-type", value: .string("endOfInputEvent")))
 9948 |             case .authchallengeresponseevent(let value):

Correct codegen so that these warnings are not received.

Expected Behavior

SDK should build without warnings.

Current Behavior

SDK builds with the warnings listed above.

Reproduction Steps

Build the AWSWAFV2 and AWSQBusiness services
Observe the compiler warnings

Possible Solution

No response

Additional Information/Context

No response

AWS SWIFT SDK version used

1.0.3 / latest

Compiler and Version used

Xcode 16.0

Operating System and version

macOS 14

@jbelkins jbelkins added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2024
@jbelkins
Copy link
Contributor Author

In the case of AWSWAFV2 above, the cause is that the property being modified is @Indirect:

    public struct NotStatement: Swift.Sendable {
        /// The statement to negate. You can use any statement that can be nested.
        /// This member is required.
        @Indirect public var statement: WAFV2ClientTypes.Statement?

        public init(
            statement: WAFV2ClientTypes.Statement? = nil
        )
        {
            self.statement = statement
        }
    }

@jbelkins
Copy link
Contributor Author

In the case of AWSQBusiness, the value is a struct with no members that is being written to an event stream.

    public struct EndOfInputEvent: Swift.Sendable {

        public init() { }
    }

The generated code only sends an :event-type in this event message:

 headers.append(.init(name: ":event-type", value: .string("endOfInputEvent")))

It is worth investigation to see if this creates a valid message on the event stream.

@jbelkins jbelkins removed the needs-triage This issue or PR still needs to be triaged. label Sep 23, 2024
@jbelkins
Copy link
Contributor Author

The second of these is fixed here:
smithy-lang/smithy-swift#839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant