From 7dc1d627d789c4f1ba475bd3dd41a4a3e3c932e7 Mon Sep 17 00:00:00 2001 From: Prabhat Sachdeva Date: Wed, 13 Sep 2023 02:05:23 +0530 Subject: [PATCH] Explorer: Print self pattern for callable declarations (#3216) When printing callable declarations, it does not print the self pattern in the deduced bindings. Example: User code: ``` class A { fn Fun[self: Self]() {} } ``` Print output is missing the self pattern ``` class A { fn Fun () { } } ``` This PR fixes it and includes the self pattern in the print output. ``` class A { fn Fun [self: Self]() { } } ``` --------- Co-authored-by: Geoff Romer --- explorer/ast/declaration.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/explorer/ast/declaration.cpp b/explorer/ast/declaration.cpp index f1bfce8d14f0..b04f18e8ddb0 100644 --- a/explorer/ast/declaration.cpp +++ b/explorer/ast/declaration.cpp @@ -415,12 +415,15 @@ void CallableDeclaration::PrintIndent(int indent_num_spaces, auto name = GetName(*this); CARBON_CHECK(name) << "Unexpected missing name for `" << *this << "`."; out.indent(indent_num_spaces) << "fn " << *name << " "; - if (!deduced_parameters_.empty()) { + if (!deduced_parameters_.empty() || self_pattern_) { out << "["; llvm::ListSeparator sep; for (Nonnull deduced : deduced_parameters_) { out << sep << *deduced; } + if (self_pattern_) { + out << sep << **self_pattern_; + } out << "]"; } out << *param_pattern_;