Skip to content

Commit

Permalink
chore: validate union members in type_definition.is_scalar() (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Jan 25, 2023
1 parent d1cdeea commit 53e2890
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tree/definition/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TypeDefinition {
matches!(self, Self::Never(_) | Self::Void(_))
}

pub fn is_scalar(&self) -> bool {
pub fn is_scalar(&self, include_union: bool) -> bool {
match &self {
Self::Literal(literal) => !matches!(literal, Literal::Null(_)),
| Self::Boolean(_)
Expand All @@ -115,6 +115,9 @@ impl TypeDefinition {
// class, and interface are represented as strings at runtime, so they are considered scalars
| Self::Class(_, _)
| Self::Interface(_, _) => true,
Self::Union(definitions) if include_union => {
definitions.iter().all(|definition| definition.is_scalar(true))
},
_ => false,
}
}
Expand Down

0 comments on commit 53e2890

Please sign in to comment.