Skip to content

feat: Change if / else blocks logic #59

@cernec1999

Description

@cernec1999

Currently, we construct if / else statements separately:

/// Creates a new if statement
pub fn new_if<C, E>(condition: C, then_block: Vec<E>) -> ControlFlowNode
where
    C: Into<ExprKind>,
    E: Into<AstKind>,
{
    ControlFlowNode::new(
        ControlFlowType::If,
        Some(condition),
        then_block
            .into_iter()
            .map(Into::into)
            .collect::<Vec<AstKind>>(),
    )
}

/// Creates a new else statement
pub fn new_else<T>(else_block: Vec<T>) -> ControlFlowNode
where
    T: Into<AstKind>,
{
    ControlFlowNode::new(
        ControlFlowType::Else,
        None::<ExprKind>,
        else_block
            .into_iter()
            .map(Into::into)
            .collect::<Vec<AstKind>>(),
    )
}

Instead, we should shift to a unified if / else block with an optional else body if one exists. This will make transformations easier.

We will need to change ControlFlowNode to reflect this change.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions