Skip to content

Conversation

@colinrozzi
Copy link
Contributor

Single-element tuples in Rust require a trailing comma to distinguish them from parentheses used for grouping. The generator was producing (String) instead of (String,) for single-element tuples, causing compilation errors.

This fix adds logic to append a comma when generating single-element tuples in the TypeDefKind::Tuple case.

I have added a conditional after the tuple loop and a test for the expected behavior, let me know if there is anything else I should do!

Single-element tuples in Rust require a trailing comma to distinguish
them from parentheses used for grouping. The generator was producing
(String) instead of (String,) for single-element tuples, causing
compilation errors.

This fix adds logic to append a comma when generating single-element
tuples in the TypeDefKind::Tuple case.
Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

}
if t.types.len() == 1 {
source.push(',');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, can we rewrite the loop body above this statement to be:

self.print_type(ty, trie, source)?;
source.push_str(", ");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! Should we remove the training comma for multi-element tuples or leave it for a formatter to take care of?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatter will take care of it, and its valid syntax even if not, so I think its fine to leave it in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect sounds good

@pchickey pchickey merged commit a74f597 into bytecodealliance:main Jun 3, 2025
6 checks passed
@colinrozzi colinrozzi deleted the fix/single-element-tuple-generation branch June 3, 2025 18:28
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.

2 participants