Skip to content

Commit 1ff3225

Browse files
committed
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.
1 parent 95d8876 commit 1ff3225

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/parser/context-decls.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ bool ParseDeclsCtx::skipFunctionBody() {
329329
}
330330
continue;
331331
}
332+
// Avoid confusion due to parens inside strings by skipping strings as a
333+
// unit.
334+
if (in.takeString()) {
335+
continue;
336+
}
332337
in.take(1);
333338
in.advance();
334339
}

test/lit/wat-kitchen-sink.wast

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,4 +5273,11 @@
52735273
)
52745274
)
52755275
)
5276+
5277+
(func $paren-in-string
5278+
;; We should not be tripped up by an extra close parenthesis inside a string.
5279+
(drop
5280+
(string.const ")")
5281+
)
5282+
)
52765283
)

0 commit comments

Comments
 (0)