Skip to content

Commit ce5cba2

Browse files
WAT: Check expression parser parsed the entire function body
1 parent c8dc624 commit ce5cba2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/WAT/Parser/WatParser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ struct WatParser {
8787
let (type, typeIndex) = try wat.types.resolve(use: typeUse)
8888
var parser = try ExpressionParser<V>(type: type, locals: locals, lexer: body, features: features)
8989
try parser.parse(visitor: &visitor, wat: &wat)
90+
// Check if the parser has reached the end of the function body
91+
guard try parser.parser.isEndOfParen() else {
92+
throw WatParserError("unexpected token", location: parser.parser.lexer.location())
93+
}
9094
return typeIndex
9195
}
9296
}

Tests/WATTests/EncoderTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class EncoderTests: XCTestCase {
107107

108108
var stats = CompatibilityTestStats()
109109
let excluded: [String] = [
110-
"token.wast",
111110
"utf8-invalid-encoding.wast"
112111
]
113112
for wastFile in Spectest.wastFiles(include: [], exclude: excluded) {

0 commit comments

Comments
 (0)