Skip to content

Commit c295f05

Browse files
authored
[clang-repl] Improve error message on failed undos (#149396)
Updated error message logic for undo function. Throws different errors for the case of there being nothing to undo, and for the case of requesting more undos than there are operations to undo. Fixes #143668
1 parent 2a5cd50 commit c295f05

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,18 @@ Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const {
761761

762762
llvm::Error Interpreter::Undo(unsigned N) {
763763

764-
if (N > getEffectivePTUSize())
764+
if (getEffectivePTUSize() == 0) {
765765
return llvm::make_error<llvm::StringError>("Operation failed. "
766-
"Too many undos",
766+
"No input left to undo",
767767
std::error_code());
768+
} else if (N > getEffectivePTUSize()) {
769+
return llvm::make_error<llvm::StringError>(
770+
llvm::formatv(
771+
"Operation failed. Wanted to undo {0} inputs, only have {1}.", N,
772+
getEffectivePTUSize()),
773+
std::error_code());
774+
}
775+
768776
for (unsigned I = 0; I < N; I++) {
769777
if (IncrExecutor) {
770778
if (llvm::Error Err = IncrExecutor->removeModule(PTUs.back()))

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ TEST_F(InterpreterTest, UndoCommand) {
160160

161161
// Fail to undo.
162162
auto Err1 = Interp->Undo();
163-
EXPECT_EQ("Operation failed. Too many undos",
163+
EXPECT_EQ("Operation failed. No input left to undo",
164164
llvm::toString(std::move(Err1)));
165165
auto Err2 = Interp->Parse("int foo = 42;");
166166
EXPECT_TRUE(!!Err2);
167167
auto Err3 = Interp->Undo(2);
168-
EXPECT_EQ("Operation failed. Too many undos",
168+
EXPECT_EQ("Operation failed. Wanted to undo 2 inputs, only have 1.",
169169
llvm::toString(std::move(Err3)));
170170

171171
// Succeed to undo.

0 commit comments

Comments
 (0)