Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking of delegate target block kind. #1605

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/type-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ Result TypeChecker::OnDelegate(Index depth) {
// Delegate starts counting after the current try, as the delegate
// instruction is not actually in the try block.
CHECK_RESULT(GetLabel(depth + 1, &label));
if (Failed(Check2LabelTypes(label, LabelType::Try, LabelType::Func))) {
PrintError("try-delegate must target a try block or function label");
result = Result::Error;
}

Label* try_label;
CHECK_RESULT(TopLabel(&try_label));
Expand Down
36 changes: 36 additions & 0 deletions test/typecheck/bad-delegate-target.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;;; TOOL: wat2wasm
;;; ERROR: 1
;;; ARGS: --enable-exceptions
(module
(event $e)
(func
try
block
try
throw $e
delegate 0
end
catch $e
loop
try
throw $e
delegate 0
end
try
catch $e
try
delegate 0
catch_all
end
end))
(;; STDERR ;;;
out/test/typecheck/bad-delegate-target.txt:9:9: error: try-delegate must target a try block or function label
try
^^^
out/test/typecheck/bad-delegate-target.txt:15:7: error: try-delegate must target a try block or function label
try
^^^
out/test/typecheck/bad-delegate-target.txt:21:7: error: try-delegate must target a try block or function label
try
^^^
;;; STDERR ;;)
3 changes: 2 additions & 1 deletion test/typecheck/delegate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
(event $e)
(func
try
block
try
try
throw $e
delegate 0
catch $e
end
catch $e
end)
Expand Down