mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
package ExplorerTest api;
|
||||
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/basic_syntax/fail_alternative_not_type.carbon:[[@LINE+1]]: type error in type expression: '(i32)' is not implicitly convertible to 'type'
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/basic_syntax/fail_alternative_not_type.carbon:[[@LINE+1]]: type error in type expression: '(i32,)' is not implicitly convertible to 'type'
|
||||
choice C { X(42) }
|
||||
|
||||
fn Main() -> i32 {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ fn F[T:! Foo](x: T) {}
|
||||
fn Main() -> i32 {
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/impl_match/fail_tuple_recurse.carbon:[[@LINE+3]]: impl matching recursively performed a more complex match using the same impl
|
||||
// CHECK:STDERR: outer match: i32 as interface Foo
|
||||
// CHECK:STDERR: inner match: (i32) as interface Foo
|
||||
// CHECK:STDERR: inner match: (i32,) as interface Foo
|
||||
F(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ class Point {
|
||||
fn Scale[self: Point](v: i32) -> i32 {
|
||||
return 0;
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_impl_bad_member.carbon:[[@LINE+3]]: type error in member of implementation
|
||||
// CHECK:STDERR: expected: fn (i32) -> class Point
|
||||
// CHECK:STDERR: actual: fn (i32) -> i32
|
||||
// CHECK:STDERR: expected: fn (i32,) -> class Point
|
||||
// CHECK:STDERR: actual: fn (i32,) -> i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ package ExplorerTest api;
|
||||
fn Main() -> i32 {
|
||||
var t1: (i32, i32) = (5, 2);
|
||||
var t2: (i32,) = (5,);
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/tuple/fail_equality_type.carbon:[[@LINE+1]]: (i32, i32) is not equality comparable with (i32) (could not find implementation of interface EqWith(U = (i32)) for (i32, i32))
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/tuple/fail_equality_type.carbon:[[@LINE+1]]: (i32, i32) is not equality comparable with (i32,) (could not find implementation of interface EqWith(U = (i32,)) for (i32, i32))
|
||||
if (t1 == t2) {
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user