Fix infinite loop

Fix the infinite loop caused by 6e459fecb794666fb7d1ddc25b93a025eed1bf40.
That commit changed the behaviour of a sem::Statement::Block method for
sem::BlockStatement instances. Now, the method returns the block itself
instead of the outer block which causes an infinite loop when iterating
over a chain of blocks.

Change-Id: I0eab3f7f166dbe38477bbefd222edb9cf0da53b5
Kokoro: Kokoro <>
Commit-Queue: Vasyl Teliman <>
Reviewed-by: Ben Clayton <>
Reviewed-by: Ryan Harrison <>
diff --git a/fuzzers/tint_ast_fuzzer/util.h b/fuzzers/tint_ast_fuzzer/util.h
index ec2f5ee..d851511 100644
--- a/fuzzers/tint_ast_fuzzer/util.h
+++ b/fuzzers/tint_ast_fuzzer/util.h
@@ -19,6 +19,7 @@
 #include "src/ast/module.h"
 #include "src/ast/variable_decl_statement.h"
+#include "src/castable.h"
 #include "src/program.h"
 #include "src/sem/block_statement.h"
 #include "src/sem/statement.h"
@@ -51,7 +52,8 @@
   std::vector<const sem::Variable*> result;
   // Walk up the hierarchy of blocks in which `curr_stmt` is contained.
-  for (const auto* block = curr_stmt->Block(); block; block = block->Block()) {
+  for (const auto* block = curr_stmt->Block(); block;
+       block = tint::As<sem::BlockStatement>(block->Parent())) {
     for (const auto* stmt : *block->Declaration()) {
       if (stmt == curr_stmt->Declaration()) {
         // `curr_stmt` was found. This is only possible if `block is the