diff options
author | KarlSchimpf <karlschimpf@gmail.com> | 2017-06-24 15:08:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 15:08:13 -0700 |
commit | d95e53d6005bc96c9db7624e5679d21969a1245b (patch) | |
tree | a2223d89b635bd1e2d438a0772bd1ce7abfd338b /src | |
parent | 4df75ce065c26b0c0244964e924692f19df17111 (diff) | |
download | wabt-d95e53d6005bc96c9db7624e5679d21969a1245b.tar.gz wabt-d95e53d6005bc96c9db7624e5679d21969a1245b.tar.bz2 wabt-d95e53d6005bc96c9db7624e5679d21969a1245b.zip |
Clean up errors messages for bad rethrow instruction. (#528)
Diffstat (limited to 'src')
-rw-r--r-- | src/type-checker.cc | 19 | ||||
-rw-r--r-- | src/validator.cc | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/type-checker.cc b/src/type-checker.cc index 2881d391..70a1d659 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -463,10 +463,21 @@ Result TypeChecker::OnRethrow(Index depth) { Label* label; CHECK_RESULT(GetLabel(depth, &label)); if (label->label_type != LabelType::Catch) { - // TODO(karlschimpf) Make this error more readable (readers - // typically think in terms of try/catch clauses, not all blocks). - PrintError("invalid rethrow depth: %" PRIindex " (max %" PRIzd ")", depth, - label_stack_.size() - 1); + std::string candidates; + size_t last = label_stack_.size() - 1; + for (size_t i = 0; i < label_stack_.size(); ++i) { + if (label_stack_[last - i].label_type == LabelType::Catch) { + if (!candidates.empty()) + candidates.append(", "); + candidates.append(std::to_string(i)); + } + } + if (candidates.empty()) { + PrintError("Rethrow not in try catch block"); + } else { + PrintError("invalid rethrow depth: %" PRIindex " (catches: %s)", depth, + candidates.c_str()); + } result = Result::Error; } CHECK_RESULT(SetUnreachable()); diff --git a/src/validator.cc b/src/validator.cc index 2a984224..ab635719 100644 --- a/src/validator.cc +++ b/src/validator.cc @@ -548,8 +548,6 @@ void Validator::CheckExpr(const Expr* expr) { break; case ExprType::Rethrow: - if (try_contexts_.empty() || try_contexts_.back().catch_ == nullptr) - PrintError(&expr->loc, "Rethrow not in try catch block"); typechecker_.OnRethrow(expr->As<RethrowExpr>()->var.index); break; |