From 1ff3225c22b9e484f81d9da4eba30b9dd208b35b Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 16 Apr 2026 12:54:18 -0700 Subject: [PATCH] Handle strings when skipping function bodies Explicitly parse strings in the logic for mostly skipping function bodies in the first parser phase. This avoids parentheses inside strings causing the parser to skip too much or too little of the input. --- src/parser/context-decls.cpp | 5 +++++ test/lit/wat-kitchen-sink.wast | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp index 73327bd1640..3afa960ee5a 100644 --- a/src/parser/context-decls.cpp +++ b/src/parser/context-decls.cpp @@ -329,6 +329,11 @@ bool ParseDeclsCtx::skipFunctionBody() { } continue; } + // Avoid confusion due to parens inside strings by skipping strings as a + // unit. + if (in.takeString()) { + continue; + } in.take(1); in.advance(); } diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 9e3c6171f4b..aeaf68182a6 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -5273,4 +5273,11 @@ ) ) ) + + (func $paren-in-string + ;; We should not be tripped up by an extra close parenthesis inside a string. + (drop + (string.const ")") + ) + ) )