@@ -771,18 +771,26 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
771771 if (!debugRepl || inDebugger)
772772 return ;
773773
774- auto dts =
775- error && expr.getPos ()
776- ? std::make_unique<DebugTraceStacker>(
777- *this ,
778- DebugTrace {
779- .pos = error->info ().pos ? error->info ().pos : positions[expr.getPos ()],
774+ auto dts = [&]() -> std::unique_ptr<DebugTraceStacker> {
775+ if (error && expr.getPos ()) {
776+ auto trace = DebugTrace{
777+ .pos = [&]() -> std::variant<Pos, PosIdx> {
778+ if (error->info ().pos ) {
779+ if (auto * pos = error->info ().pos .get ())
780+ return *pos;
781+ return noPos;
782+ }
783+ return expr.getPos ();
784+ }(),
780785 .expr = expr,
781786 .env = env,
782787 .hint = error->info ().msg ,
783- .isError = true
784- })
785- : nullptr ;
788+ .isError = true };
789+
790+ return std::make_unique<DebugTraceStacker>(*this , std::move (trace));
791+ }
792+ return nullptr ;
793+ }();
786794
787795 if (error)
788796 {
@@ -827,7 +835,7 @@ static std::unique_ptr<DebugTraceStacker> makeDebugTraceStacker(
827835 EvalState & state,
828836 Expr & expr,
829837 Env & env,
830- std::shared_ptr <Pos> && pos,
838+ std::variant <Pos, PosIdx> pos,
831839 const Args & ... formatArgs)
832840{
833841 return std::make_unique<DebugTraceStacker>(state,
@@ -1104,7 +1112,7 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial)
11041112 *this ,
11051113 *e,
11061114 this ->baseEnv ,
1107- e->getPos () ? std::make_shared<Pos>(positions[e-> getPos ()]) : nullptr ,
1115+ e->getPos (),
11081116 " while evaluating the file '%1%':" , resolvedPath.to_string ())
11091117 : nullptr ;
11101118
@@ -1330,9 +1338,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
13301338 state,
13311339 *this ,
13321340 env2,
1333- getPos ()
1334- ? std::make_shared<Pos>(state.positions [getPos ()])
1335- : nullptr ,
1341+ getPos (),
13361342 " while evaluating a '%1%' expression" ,
13371343 " let"
13381344 )
@@ -1401,7 +1407,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
14011407 state,
14021408 *this ,
14031409 env,
1404- state. positions [ getPos ()] ,
1410+ getPos (),
14051411 " while evaluating the attribute '%1%'" ,
14061412 showAttrPath (state, env, attrPath))
14071413 : nullptr ;
@@ -1602,7 +1608,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
16021608 try {
16031609 auto dts = debugRepl
16041610 ? makeDebugTraceStacker (
1605- *this , *lambda.body , env2, positions[ lambda.pos ] ,
1611+ *this , *lambda.body , env2, lambda.pos ,
16061612 " while calling %s" ,
16071613 lambda.name
16081614 ? concatStrings (" '" , symbols[lambda.name ], " '" )
@@ -1737,9 +1743,7 @@ void ExprCall::eval(EvalState & state, Env & env, Value & v)
17371743 state,
17381744 *this ,
17391745 env,
1740- getPos ()
1741- ? std::make_shared<Pos>(state.positions [getPos ()])
1742- : nullptr ,
1746+ getPos (),
17431747 " while calling a function"
17441748 )
17451749 : nullptr ;
@@ -2123,7 +2127,7 @@ void EvalState::forceValueDeep(Value & v)
21232127 try {
21242128 // If the value is a thunk, we're evaling. Otherwise no trace necessary.
21252129 auto dts = debugRepl && i.value ->isThunk ()
2126- ? makeDebugTraceStacker (*this , *i.value ->payload .thunk .expr , *i.value ->payload .thunk .env , positions[ i.pos ] ,
2130+ ? makeDebugTraceStacker (*this , *i.value ->payload .thunk .expr , *i.value ->payload .thunk .env , i.pos ,
21272131 " while evaluating the attribute '%1%'" , symbols[i.name ])
21282132 : nullptr ;
21292133
0 commit comments