mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 07:31:04 +01:00
fix printing for single element tuple values (#2786)
adds trailing comma to single element tuple
example:
```carbon
package ExplorerTest api;
fn Main() -> i32
{
var a: (i32,) = (1, 2);
return 0;
}
```
change in error message:
```diff
-type error in initializer of variable: '(i32, i32)' is not implicitly convertible to '(i32)'
+type error in initializer of variable: '(i32, i32)' is not implicitly convertible to '(i32,)'
```
This commit is contained in:
@@ -414,10 +414,14 @@ void Value::Print(llvm::raw_ostream& out) const {
|
||||
case Value::Kind::TupleValue: {
|
||||
out << "(";
|
||||
llvm::ListSeparator sep;
|
||||
for (Nonnull<const Value*> element :
|
||||
cast<TupleValueBase>(*this).elements()) {
|
||||
const auto elements = cast<TupleValueBase>(*this).elements();
|
||||
for (Nonnull<const Value*> element : elements) {
|
||||
out << sep << *element;
|
||||
}
|
||||
// Print trailing comma for single element tuples: (i32,).
|
||||
if (elements.size() == 1) {
|
||||
out << ",";
|
||||
}
|
||||
out << ")";
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user