Skip to content

standalone ifs being statements breaks oneof type #72

Description

@InnocentZero

if let Some(else_blk) = else_block {
let else_type_id =
if let AstNode::Block(_) = self.compiler.ast_nodes[else_blk.0] {
self.typecheck_block(else_blk, expected)
} else {
self.typecheck_expr(else_blk, expected)
};
let mut types = HashSet::new();
types.insert(then_type_id);
types.insert(else_type_id);
self.create_oneof(types)
} else {
// If there's no else block, the if expression is a statement
NONE_TYPE
}

The comment on the else branch here is wrong since

let x = if $y < $z { 1 }

should resolve the type of $x to oneof<nothing, int>, not nothing. This breaks oneof type semantics that nushell currently uses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions