Skip to content

Commit

Permalink
Allow reading field lists with packed types (#30)
Browse files Browse the repository at this point in the history
Field lists were parsed correctly for value types (e.g. `(field i32)`),
but not for packed types (e.g. `(field i8)`)
  • Loading branch information
binji authored Nov 19, 2020
1 parent 45f56c0 commit aaafda2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/text/read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool IsFieldTypeContents(Tokenizer& tokenizer) {
auto token = tokenizer.Peek();
return (token.type == TokenType::Lpar &&
tokenizer.Peek(1).type == TokenType::Mut) ||
IsValueType(tokenizer);
IsValueType(tokenizer) || token.type == TokenType::PackedType;
}

auto ReadFieldTypeContents(Tokenizer& tokenizer, Context& context)
Expand Down
9 changes: 9 additions & 0 deletions test/text/read_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,15 @@ TEST_F(TextReadTest, FieldTypeList) {
Mutability::Const}}},
"(field i32)"_su8);

// Packed field
OK(ReadFieldTypeList,
FieldTypeList{
At{"i8"_su8,
FieldType{nullopt,
At{"i8"_su8, StorageType{At{"i8"_su8, PackedType::I8}}},
Mutability::Const}}},
"(field i8)"_su8);

// Combined fields
OK(ReadFieldTypeList,
FieldTypeList{
Expand Down

0 comments on commit aaafda2

Please sign in to comment.