aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/nixexpr.cc
diff options
context:
space:
mode:
authorpiegames <git@piegames.de>2024-10-15 12:55:29 +0200
committerpiegames <git@piegames.de>2024-10-18 11:40:04 +0000
commit878e18188215ad52784027c3489c7b4f6f0bcba3 (patch)
treef69527e37f4b457cf5ffe3dcf4389a39856b8239 /src/libexpr/nixexpr.cc
parentc852ae60da16b890f77e9e1b274d31dced73ae66 (diff)
libexpr: Print interpolations more accurately in `show`
This is only a minor semantical distinction, but we should be able to properly test it, and the parser tests rely on show for that. Change-Id: I25e868cf9544e30cdff17deb5fd50a434e0f367e
Diffstat (limited to 'src/libexpr/nixexpr.cc')
-rw-r--r--src/libexpr/nixexpr.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 4b659b71a..0c1a1ec0e 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -247,9 +247,24 @@ void ExprConcatStrings::show(const SymbolTable & symbols, std::ostream & str) co
{
bool first = true;
str << "(";
- for (auto & i : es) {
- if (first) first = false; else str << " + ";
- i.second->show(symbols, str);
+ for (auto & [_pos, part] : es) {
+ if (first)
+ first = false;
+ else
+ str << " + ";
+
+ if (forceString && !dynamic_cast<ExprString *>(part.get())) {
+ /* Print as a string with an interpolation, to preserve the
+ * semantics of the value having to be a string.
+ * Interpolations are weird and someone should eventually
+ * move them out into their own AST node please.
+ */
+ str << "\"${";
+ part->show(symbols, str);
+ str << "}\"";
+ } else {
+ part->show(symbols, str);
+ }
}
str << ")";
}