checker: fix assign error assigning sum type to non sum type. closes #7233
parent
d7ff342ab3
commit
5c213de003
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue