sway_core/language/ty/expression/
scrutinee.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use sway_types::{Ident, Span};

use crate::{
    decl_engine::{DeclRefEnum, DeclRefStruct},
    language::{ty::*, *},
    type_system::*,
};

#[derive(Debug, Clone)]
pub struct TyScrutinee {
    pub variant: TyScrutineeVariant,
    pub type_id: TypeId,
    pub span: Span,
}

#[derive(Debug, Clone)]
pub enum TyScrutineeVariant {
    Or(Vec<TyScrutinee>),
    CatchAll,
    Literal(Literal),
    Variable(Ident),
    Constant(Ident, Literal, TyConstantDecl),
    StructScrutinee {
        struct_ref: DeclRefStruct,
        fields: Vec<TyStructScrutineeField>,
        instantiation_call_path: CallPath,
    },
    EnumScrutinee {
        enum_ref: DeclRefEnum,
        variant: Box<TyEnumVariant>,
        /// Should contain a TyDecl to either an enum or a type alias.
        call_path_decl: ty::TyDecl,
        value: Box<TyScrutinee>,
        instantiation_call_path: CallPath,
    },
    Tuple(Vec<TyScrutinee>),
}

#[derive(Debug, Clone)]
pub struct TyStructScrutineeField {
    pub field: Ident,
    pub scrutinee: Option<TyScrutinee>,
    pub span: Span,
    pub field_def_name: Ident,
}