Skip to content

Commit

Permalink
Fixed issue 77; pub incorrectly consuming a field type
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorKoenders committed Nov 27, 2023
1 parent 591ef63 commit 8fcda2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/parse/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ fn test_struct_body_take() {
}
}

#[test]
fn issue_77() {
// https://github.com/bincode-org/virtue/issues/77
use crate::token_stream;

let stream = &mut token_stream("struct Test(pub [u8; 32])");
let (data_type, ident) = super::DataType::take(stream).unwrap();
assert_eq!(data_type, super::DataType::Struct);
assert_eq!(ident, "Test");
let body = StructBody::take(stream).unwrap();
let fields = body.fields.unwrap();
let Fields::Tuple(t) = fields else {
panic!("Fields is not a tuple")
};
assert_eq!(t.len(), 1);
assert_eq!(t[0].r#type[0].to_string(), "[u8 ; 32 ]");
}

/// The body of an enum
#[derive(Debug)]
pub struct EnumBody {
Expand Down
10 changes: 6 additions & 4 deletions src/parse/visibility.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::utils::*;
use crate::prelude::TokenTree;
use crate::prelude::{Delimiter, TokenTree};
use crate::Result;
use std::iter::Peekable;

Expand All @@ -21,9 +21,11 @@ impl Visibility {
assume_ident(input.next());

// check if the next token is `pub(...)`
if let Some(TokenTree::Group(_)) = input.peek() {
// we just consume the visibility, we're not actually using it for generation
assume_group(input.next());
if let Some(TokenTree::Group(g)) = input.peek() {
if g.delimiter() == Delimiter::Parenthesis {
// we just consume the visibility, we're not actually using it for generation
assume_group(input.next());
}
}

Ok(Visibility::Pub)
Expand Down

0 comments on commit 8fcda2b

Please sign in to comment.