checker: fix assign error assigning sum type to non sum type. closes #7233

pull/7270/head
joe-conigliaro 2020-12-11 21:38:53 +11:00
parent d7ff342ab3
commit 5c213de003
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
2 changed files with 2 additions and 6 deletions

View File

@ -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

View File

@ -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)