From 33cce995560483718045252348b9c075ce6dab40 Mon Sep 17 00:00:00 2001 From: "r@l" Date: Tue, 24 Mar 2026 11:28:00 +0100 Subject: [PATCH] Fix single-element tuple Sway syntax to use trailing comma 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) --- src/sway_converter.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sway_converter.rs b/src/sway_converter.rs index 81874de..b3dfde5 100644 --- a/src/sway_converter.rs +++ b/src/sway_converter.rs @@ -135,7 +135,11 @@ impl SwayConverter { ParamType::StringSlice => "str".to_string(), ParamType::Tuple(types) => { let values: Vec = types.iter().map(|p| self.get_type(p)).collect(); - format!("({})", values.join(", ")) + if values.len() == 1 { + format!("({},)", values[0]) + } else { + format!("({})", values.join(", ")) + } } ParamType::Array(element_type, size) => { let string_element_type = self.get_type(element_type); @@ -211,7 +215,11 @@ impl SwayConverter { all_values.iter().cloned().unzip(); ( - format!("({})", values.join(", ")), + if values.len() == 1 { + format!("({},)", values[0]) + } else { + format!("({})", values.join(", ")) + }, decls.into_iter().flatten().collect(), ) }