From f18c33b24937f66d857fe098887bb08991bea721 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 3 Jul 2024 14:43:34 -0400 Subject: [PATCH] xo-expression: bugfix: ensure in-layer uniqueness of vars --- include/xo/expression/Variable.hpp | 5 +++++ src/expression/Lambda.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/xo/expression/Variable.hpp b/include/xo/expression/Variable.hpp index 713da66f..8ca2cb2b 100644 --- a/include/xo/expression/Variable.hpp +++ b/include/xo/expression/Variable.hpp @@ -25,6 +25,11 @@ namespace xo { return new Variable(name, var_type); } + /** return copy of x: same var, different object identity **/ + static ref::rp copy(ref::brw x) { + return new Variable(x->name(), x->valuetype()); + } + /** downcast from Expression **/ static ref::brw from(ref::brw x) { return ref::brw::from(x); diff --git a/src/expression/Lambda.cpp b/src/expression/Lambda.cpp index 833c998f..72459fe5 100644 --- a/src/expression/Lambda.cpp +++ b/src/expression/Lambda.cpp @@ -103,9 +103,11 @@ namespace xo { auto ix = var_map.find(var->name()); if (ix == var_map.end()) { - /* add to var_map */ + /* add to var_map, copy to ensure Variable + * is unique to layer + */ - var_map[var->name()] = var.get(); + var_map[var->name()] = Variable::copy(var); return var.get(); } else {