From 32c99313a6d3e2cc551c79f2dd35a17a6f35ba3e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 23 Aug 2022 16:40:39 +0100 Subject: [PATCH] AK: Warn when trying to set `@foo@` as a SourceGenerator key I was very confused why I was getting "no key named `foo`" errors, so hopefully this will save someone that confusion in the future. :^) (It'll probably be me again...) --- AK/SourceGenerator.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/AK/SourceGenerator.h b/AK/SourceGenerator.h index 23adb74499b..526c8ac4808 100644 --- a/AK/SourceGenerator.h +++ b/AK/SourceGenerator.h @@ -37,7 +37,15 @@ public: SourceGenerator fork() { return SourceGenerator { m_builder, m_mapping, m_opening, m_closing }; } - void set(StringView key, String value) { m_mapping.set(key, move(value)); } + void set(StringView key, String value) + { + if (key.contains(m_opening) || key.contains(m_closing)) { + warnln("SourceGenerator keys cannot contain the opening/closing delimiters `{}` and `{}`. (Keys are only wrapped in these when using them, not when setting them.)", m_opening, m_closing); + VERIFY_NOT_REACHED(); + } + m_mapping.set(key, move(value)); + } + String get(StringView key) const { auto result = m_mapping.get(key);