From 5cfd038bd8bcd65c45f08f6c3665cd49e6643714 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 6 Apr 2022 19:08:29 -0600 Subject: [PATCH] show expr pos if DebugTrace one is noPos --- src/libcmd/command.cc | 2 +- src/libcmd/repl.cc | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 34535802f..cc353cbb4 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -129,7 +129,7 @@ ref EvalCommand::getEvalState() new DebugTraceStacker( *evalState, DebugTrace - {.pos = *expr.getPos(), + {.pos = (error->info().errPos ? *error->info().errPos : *expr.getPos()), .expr = expr, .env = env, .hint = error->info().msg, diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 5de4cdf76..416635f16 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -412,9 +412,11 @@ std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt) out << ANSI_RED "error: " << ANSI_NORMAL; out << dt.hint.str() << "\n"; - if (dt.pos.has_value() && (*dt.pos)) { - auto pos = dt.pos.value(); - out << "\n"; + // prefer direct pos, but if noPos then try the expr. + auto pos = (*dt.pos ? *dt.pos : + (dt.expr.getPos() ? *dt.expr.getPos() : noPos)); + + if (pos) { printAtPos(pos, out); auto loc = getCodeLines(pos);