diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index d352dabae9db5c6a11858ad0c241bcecf69d87c2..009e3f85c8eb904b8aae1a22cc1301fdb1b9329d 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -1071,6 +1071,7 @@ pub enum Literal { Character(LiteralCharacter), Integer(LiteralInteger), Struct(LiteralStruct), + Enum(LiteralEnum), } impl Literal { @@ -1089,6 +1090,14 @@ impl Literal { unreachable!("Attempted to obtain {:?} as Literal::Struct", self) } } + + pub(crate) fn as_enum(&self) -> &LiteralEnum { + if let Literal::Enum(literal) = self { + literal + } else { + unreachable!("Attempted to obtain {:?} as Literal::Enum", self) + } + } } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] @@ -1106,7 +1115,7 @@ pub struct LiteralStruct { pub(crate) identifier: NamespacedIdentifier, pub(crate) fields: Vec, // Phase 2: linker - pub(crate) poly_args2: Vec, // taken from identifier + pub(crate) poly_args2: Vec, // taken from identifier once linked to a definition pub(crate) definition: Option } @@ -1115,9 +1124,9 @@ pub struct LiteralEnum { // Phase 1: parser pub(crate) identifier: NamespacedIdentifier, // Phase 2: linker - pub(crate) poly_args2: Vec, + pub(crate) poly_args2: Vec, // taken from identifier once linked to a definition pub(crate) definition: Option, - pub(crate) variant_idx: usize, + pub(crate) variant_idx: usize, // as present in the type table } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]