From 69b4b0086f49c5bd39d81031d04e51001bb6bc1d Mon Sep 17 00:00:00 2001 From: Geoff Romer Date: Tue, 13 Jul 2021 09:57:22 -0700 Subject: [PATCH] Fix infinite recursion in PrintList. (#642) Also make `Stack`'s single-argument constructor explicit, which would have helped catch this at compile time. --- executable_semantics/interpreter/action.cpp | 2 +- executable_semantics/interpreter/stack.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/executable_semantics/interpreter/action.cpp b/executable_semantics/interpreter/action.cpp index 1494aa03c23d..0db7af5dfc43 100644 --- a/executable_semantics/interpreter/action.cpp +++ b/executable_semantics/interpreter/action.cpp @@ -102,7 +102,7 @@ void Action::Print(std::ostream& out) { void Action::PrintList(Stack ls, std::ostream& out) { if (!ls.IsEmpty()) { - PrintList(ls.Pop(), out); + ls.Pop()->Print(out); if (!ls.IsEmpty()) { out << " :: "; PrintList(ls, out); diff --git a/executable_semantics/interpreter/stack.h b/executable_semantics/interpreter/stack.h index ab233b5b9306..9fffa129f266 100644 --- a/executable_semantics/interpreter/stack.h +++ b/executable_semantics/interpreter/stack.h @@ -57,7 +57,7 @@ struct Stack { Stack() { head = nullptr; } // Creates an instance containing just `x`. - Stack(T x) : Stack() { Push(x); } + explicit Stack(T x) : Stack() { Push(x); } // Pushes `x` onto the top of the stack. void Push(T x) { head = new ListNode(x, head); }