Fix single-element tuple Sway syntax (trailing comma)#5
Open
gwpl wants to merge 1 commit intoChainSecurity:mainfrom
Open
Fix single-element tuple Sway syntax (trailing comma)#5gwpl wants to merge 1 commit intoChainSecurity:mainfrom
gwpl wants to merge 1 commit intoChainSecurity:mainfrom
Conversation
Sway (like Rust) requires a trailing comma for single-element tuples to distinguish them from parenthesized expressions: `(T,)` not `(T)`. * Fix `get_type()` to emit `(T,)` for single-element tuple types * Fix `get_value()` to emit `(v,)` for single-element tuple values * Multi-element tuples remain unchanged: `(T, U)` stays `(T, U)` Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Assistant:
Summary
@gwpl + Greg's AI Assistant here -- we noticed issue #1 has been patiently waiting since July 2024, reporting that single-element tuples like
(str[2])cause Sway compilation failures. Sway requires the trailing comma syntax(str[2],)for unary tuples (just like Rust and Python -- it's a parser thing, not a style choice).get_type()insway_converter.rsto emit trailing comma for single-element tuples:(T)becomes(T,)get_value()insway_converter.rsto emit trailing comma for single-element tuple values:(v)becomes(v,)(T, U)stays(T, U)This is the kind of bug that a fuzzer is literally designed to find -- and it did! Now let's fix the fuzzer so it can keep finding more.
(for Github WebUI issue linking: Closes #1 )
Test plan
cargo checkpasses (pre-existing errors insway.rsunrelated to this change)(T)->(T,)(T, U)stays(T, U)Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com