diff --git a/src/clone_context.h b/src/clone_context.h index 34e366b27c..e3d8b14884 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -124,14 +124,14 @@ class CloneContext { // version instead of making yet another copy. auto it = cloned_.find(a); if (it != cloned_.end()) { - return CheckedCast(it->second); + return CheckedCast(it->second); } // First time clone and no replacer transforms matched. // Clone with T::Clone(). auto* c = a->Clone(this); cloned_.emplace(a, c); - return CheckedCast(c); + return CheckedCast(c); } /// Clones the Source `s` into `dst` diff --git a/src/clone_context_test.cc b/src/clone_context_test.cc index 3b306805f8..5f8582e48b 100644 --- a/src/clone_context_test.cc +++ b/src/clone_context_test.cc @@ -243,6 +243,24 @@ TEST(CloneContext, CloneWithReplaceAll_Symbols) { EXPECT_EQ(cloned_root->b->b->name, cloned.Symbols().Get("transformedb>")); } +TEST(CloneContext, CloneWithoutTransform) { + ProgramBuilder builder; + auto* original_node = + builder.create(builder.Symbols().Register("root")); + Program original(std::move(builder)); + + ProgramBuilder cloned; + CloneContext ctx(&cloned, &original); + ctx.ReplaceAll([&](Node*) { + return cloned.create( + builder.Symbols().Register("")); + }); + + auto* cloned_node = ctx.CloneWithoutTransform(original_node); + EXPECT_NE(cloned_node, original_node); + EXPECT_EQ(cloned_node->name, cloned.Symbols().Get("root")); +} + TEST(CloneContext, CloneWithReplace) { ProgramBuilder builder; auto* original_root =