parser: add special Type::Void case

This commit is contained in:
Ryan Chandler 2022-09-12 12:48:52 +01:00
parent c4fdc85d64
commit 9953be3ab1
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 15 additions and 1 deletions

View File

@ -10,6 +10,7 @@ pub enum Type {
Nullable(String), Nullable(String),
Union(Vec<String>), Union(Vec<String>),
Intersection(Vec<String>), Intersection(Vec<String>),
Void,
} }
#[derive(Debug, Eq, PartialEq, Clone, Serialize)] #[derive(Debug, Eq, PartialEq, Clone, Serialize)]

View File

@ -159,7 +159,10 @@ impl Parser {
return Ok(Type::Intersection(types)); return Ok(Type::Intersection(types));
} }
Ok(Type::Plain(id)) Ok(match id.as_str() {
"void" => Type::Void,
_ => Type::Plain(id),
})
} }
fn statement(&mut self) -> ParseResult<Statement> { fn statement(&mut self) -> ParseResult<Statement> {
@ -2929,6 +2932,16 @@ mod tests {
return_type: Some(Type::Plain("string".into())), return_type: Some(Type::Plain("string".into())),
}], }],
); );
assert_ast(
"<?php function foo(): void {}",
&[Statement::Function {
name: "foo".to_string().into(),
params: vec![],
body: vec![],
return_type: Some(Type::Void),
}],
);
} }
#[test] #[test]