Skip to content

Commit

Permalink
checker: cleanup of is_sumtype_variant_infix()
Browse files Browse the repository at this point in the history
  • Loading branch information
serkonda7 committed Feb 2, 2025
1 parent 482f275 commit 07e0021
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/bait/checker/infix.bt
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,21 @@ fun (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {

// x is Variant
fun (c Checker) is_sumtype_variant_infix(mut node ast.InfixExpr) ast.Type {
mut right := node.right as ast.Ident
if right.pkg == "" and c.pkg != 'main' and c.pkg != "builtin" {
right.pkg = c.pkg
}
node.right_type = c.table.get_idx(right.full_name())

// Smartcast variable
if node.left is ast.Ident {
mut right := node.right as ast.Ident
if right.pkg == "" and c.pkg != 'main' {
right.pkg = c.pkg
}
node.right_type = c.table.get_idx(right.full_name())
left := node.left as ast.Ident
c.scope.update_type(left.full_name(), node.right_type)
return ast.BOOL_TYPE
}

// Smartcast struct field
if node.left is ast.SelectorExpr {
mut right := node.right as ast.Ident
if right.pkg == "" and c.pkg != 'main' {
right.pkg = c.pkg
}
node.right_type = c.table.get_idx(right.full_name())
left := node.left as ast.SelectorExpr
name := (left.expr as ast.Ident).full_name() + '.' + left.field_name
c.scope.update_type(name, node.right_type)
Expand Down

0 comments on commit 07e0021

Please sign in to comment.