From 07e0021164ea46e2e17602360f4f498368c62631 Mon Sep 17 00:00:00 2001 From: Lukas Neubert <40118727+serkonda7@users.noreply.github.com> Date: Sun, 2 Feb 2025 20:42:48 +0100 Subject: [PATCH] checker: cleanup of `is_sumtype_variant_infix()` --- lib/bait/checker/infix.bt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/bait/checker/infix.bt b/lib/bait/checker/infix.bt index cb64d56f..51e08cf0 100644 --- a/lib/bait/checker/infix.bt +++ b/lib/bait/checker/infix.bt @@ -58,13 +58,14 @@ 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 @@ -72,11 +73,6 @@ fun (c Checker) is_sumtype_variant_infix(mut node ast.InfixExpr) ast.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)