summaryrefslogtreecommitdiff
path: root/src/type-checker.cc
diff options
context:
space:
mode:
authorKarlSchimpf <karlschimpf@gmail.com>2017-06-24 15:08:13 -0700
committerGitHub <noreply@github.com>2017-06-24 15:08:13 -0700
commitd95e53d6005bc96c9db7624e5679d21969a1245b (patch)
treea2223d89b635bd1e2d438a0772bd1ce7abfd338b /src/type-checker.cc
parent4df75ce065c26b0c0244964e924692f19df17111 (diff)
downloadwabt-d95e53d6005bc96c9db7624e5679d21969a1245b.tar.gz
wabt-d95e53d6005bc96c9db7624e5679d21969a1245b.tar.bz2
wabt-d95e53d6005bc96c9db7624e5679d21969a1245b.zip
Clean up errors messages for bad rethrow instruction. (#528)
Diffstat (limited to 'src/type-checker.cc')
-rw-r--r--src/type-checker.cc19
1 files changed, 15 insertions, 4 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());