From a4c9ea7b5dbbd50a13f687da96e0f1587845dff6 Mon Sep 17 00:00:00 2001 From: Emily Samp Date: Mon, 13 Jan 2025 15:48:54 -0600 Subject: [PATCH] Add formatter for Prism node types When ENFORCE macros fail, they use fmt (via spdlog) to format error messages. Add a formatter specialization for pm_node_type to properly display Prism node types in these error messages. Instead of showing numeric values, the formatter uses pm_node_type_to_str to display human-readable node type names. --- parser/prism/Helpers.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/parser/prism/Helpers.h b/parser/prism/Helpers.h index 6bd1ad09d62..75361e2580a 100644 --- a/parser/prism/Helpers.h +++ b/parser/prism/Helpers.h @@ -6,6 +6,12 @@ extern "C" { #include "prism.h" } +template <> struct fmt::formatter : formatter { + auto format(pm_node_type type, format_context &ctx) const { + return formatter::format(pm_node_type_to_str(type), ctx); + } +}; + namespace sorbet::parser::Prism { // This templated `PrismNodeTypeHelper` type and its specializations work as a lookup-table that associates