From b3502f257ff12dbc3d094530c650efdfaf7c8f5d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 16 May 2021 14:59:08 -0400 Subject: [PATCH] Correct declare_variable example --- site/posts/2021-05-09-variable-declarations.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/posts/2021-05-09-variable-declarations.md b/site/posts/2021-05-09-variable-declarations.md index a2865db..c90fcd4 100644 --- a/site/posts/2021-05-09-variable-declarations.md +++ b/site/posts/2021-05-09-variable-declarations.md @@ -72,7 +72,11 @@ impl Context { } fn declare_variable(&mut self, name: &str, value: Value) { - self.variables.insert(name.into(), value); + if self.variables.contains_key(name) { + panic!("cannot re-declare variable {}", name); + } else { + self.variables.insert(name.into(), value); + } } } ```