Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stringifying tuple values. #4664

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions toolchain/check/testdata/tuple/import.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ var c_bad: C((1, 2, 3)) = F();

impl package Implicit;

// CHECK:STDERR: fail_bad_value.impl.carbon:[[@LINE+6]]:1: error: cannot implicitly convert from `C(<cannot stringify inst375 kind TupleValue>)` to `C(<cannot stringify inst363 kind TupleValue>)` [ImplicitAsConversionFailure]
// CHECK:STDERR: fail_bad_value.impl.carbon:[[@LINE+6]]:1: error: cannot implicitly convert from `C((1, 2))` to `C((3, 4))` [ImplicitAsConversionFailure]
// CHECK:STDERR: var c_bad: C((3, 4)) = F();
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_bad_value.impl.carbon:[[@LINE+3]]:1: note: type `C(<cannot stringify inst375 kind TupleValue>)` does not implement interface `ImplicitAs(C(<cannot stringify inst363 kind TupleValue>))` [MissingImplInMemberAccessNote]
// CHECK:STDERR: fail_bad_value.impl.carbon:[[@LINE+3]]:1: note: type `C((1, 2))` does not implement interface `ImplicitAs(C((3, 4)))` [MissingImplInMemberAccessNote]
// CHECK:STDERR: var c_bad: C((3, 4)) = F();
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
var c_bad: C((3, 4)) = F();
Expand Down
22 changes: 21 additions & 1 deletion toolchain/sem_ir/stringify_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,27 @@ auto StringifyTypeExpr(const SemIR::File& sem_ir, InstId outer_inst_id)
}
break;
}
case CARBON_KIND(TupleValue inst): {
auto refs = sem_ir.inst_blocks().Get(inst.elements_id);
if (refs.empty()) {
out << "()";
break;
}
out << "(";
step_stack.PushString(")");
// A tuple of one element has a comma to disambiguate from an
// expression.
if (refs.size() == 1) {
step_stack.PushString(",");
}
for (auto i : llvm::reverse(llvm::seq(refs.size()))) {
step_stack.PushInstId(refs[i]);
if (i > 0) {
step_stack.PushString(", ");
}
}
break;
}
case CARBON_KIND(UnboundElementType inst): {
out << "<unbound element of class ";
step_stack.PushString(">");
Expand Down Expand Up @@ -492,7 +513,6 @@ auto StringifyTypeExpr(const SemIR::File& sem_ir, InstId outer_inst_id)
case TupleAccess::Kind:
case TupleInit::Kind:
case TupleLiteral::Kind:
case TupleValue::Kind:
case UnaryOperatorNot::Kind:
case ValueAsRef::Kind:
case ValueOfInitializer::Kind:
Expand Down
Loading