sway_core/language/ty/expression/
scrutinee.rs

1use crate::{
2    decl_engine::{DeclRefEnum, DeclRefStruct},
3    language::{ty::*, *},
4    type_system::*,
5};
6use serde::{Deserialize, Serialize};
7use sway_types::{Ident, Span};
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct TyScrutinee {
11    pub variant: TyScrutineeVariant,
12    pub type_id: TypeId,
13    pub span: Span,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[allow(clippy::large_enum_variant)]
18pub enum TyScrutineeVariant {
19    Or(Vec<TyScrutinee>),
20    CatchAll,
21    Literal(Literal),
22    Variable(Ident),
23    Constant(Ident, Literal, TyConstantDecl),
24    StructScrutinee {
25        struct_ref: DeclRefStruct,
26        fields: Vec<TyStructScrutineeField>,
27        instantiation_call_path: CallPath,
28    },
29    EnumScrutinee {
30        enum_ref: DeclRefEnum,
31        variant: Box<TyEnumVariant>,
32        /// Should contain a TyDecl to either an enum or a type alias.
33        call_path_decl: ty::TyDecl,
34        value: Box<TyScrutinee>,
35        instantiation_call_path: CallPath,
36    },
37    Tuple(Vec<TyScrutinee>),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct TyStructScrutineeField {
42    pub field: Ident,
43    pub scrutinee: Option<TyScrutinee>,
44    pub span: Span,
45    pub field_def_name: Ident,
46}