Skip to content

Fix single-element tuple Sway syntax (trailing comma)#5

Open
gwpl wants to merge 1 commit intoChainSecurity:mainfrom
VariousForks:i1-fix-single-element-tuple-sway-syntax
Open

Fix single-element tuple Sway syntax (trailing comma)#5
gwpl wants to merge 1 commit intoChainSecurity:mainfrom
VariousForks:i1-fix-single-element-tuple-sway-syntax

Conversation

@gwpl
Copy link
Copy Markdown

@gwpl gwpl commented Mar 24, 2026

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).

  • Fix tuple type generation in get_type() in sway_converter.rs to emit trailing comma for single-element tuples: (T) becomes (T,)
  • Fix tuple value generation in get_value() in sway_converter.rs to emit trailing comma for single-element tuple values: (v) becomes (v,)
  • Multi-element tuples remain unchanged: (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 check passes (pre-existing errors in sway.rs unrelated to this change)
  • Verified fix handles single-element tuples: (T) -> (T,)
  • Multi-element tuples remain unchanged: (T, U) stays (T, U)
  • Reviewed all tuple-related code paths in sway_converter.rs (get_type, get_value, get_getters, get_declaration)

Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler issues

1 participant