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)]
17pub enum TyScrutineeVariant {
18    Or(Vec<TyScrutinee>),
19    CatchAll,
20    Literal(Literal),
21    Variable(Ident),
22    Constant(Ident, Literal, TyConstantDecl),
23    StructScrutinee {
24        struct_ref: DeclRefStruct,
25        fields: Vec<TyStructScrutineeField>,
26        instantiation_call_path: CallPath,
27    },
28    EnumScrutinee {
29        enum_ref: DeclRefEnum,
30        variant: Box<TyEnumVariant>,
31        /// Should contain a TyDecl to either an enum or a type alias.
32        call_path_decl: ty::TyDecl,
33        value: Box<TyScrutinee>,
34        instantiation_call_path: CallPath,
35    },
36    Tuple(Vec<TyScrutinee>),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct TyStructScrutineeField {
41    pub field: Ident,
42    pub scrutinee: Option<TyScrutinee>,
43    pub span: Span,
44    pub field_def_name: Ident,
45}