diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 75a9c39dcf..7c808eb5a3 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -102,7 +102,7 @@ pub fn (mut c Checker) check_basic(got table.Type, expected table.Type) bool { return true } // sum type - if c.check_sumtype_compatibility(got, expected) { + if c.table.sumtype_has_variant(expected, got) { return true } // fn type @@ -386,10 +386,6 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T return table.string_type } -pub fn (c &Checker) check_sumtype_compatibility(a table.Type, b table.Type) bool { - return c.table.sumtype_has_variant(a, b) || c.table.sumtype_has_variant(b, a) -} - pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) { gt_name := 'T' mut typ := table.void_type diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 079af02403..9da730bced 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3874,7 +3874,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) table.Type { expr_type := c.expr(infix.left) if left_sym.kind == .interface_ { c.type_implements(right_expr.typ, expr_type, branch.pos) - } else if !c.check_types(expr_type, right_expr.typ) { + } else if !c.check_types(right_expr.typ, expr_type) { expect_str := c.table.type_to_str(right_expr.typ) expr_str := c.table.type_to_str(expr_type) c.error('cannot use type `$expect_str` as type `$expr_str`', branch.pos)