v2: checker: [] and in
parent
e30bd04579
commit
92e3e48bce
|
@ -93,11 +93,15 @@ pub fn (c mut Checker) infix_expr(infix_expr ast.InfixExpr) table.Type {
|
|||
if !c.table.check(right_type, left_type) {
|
||||
left := c.table.get_type_symbol(left_type)
|
||||
right := c.table.get_type_symbol(right_type)
|
||||
// array << elm
|
||||
// `array << elm`
|
||||
// the expressions have different types (array_x and x)
|
||||
if left.kind == .array && infix_expr.op == .left_shift {
|
||||
return table.void_type
|
||||
}
|
||||
// `elm in array`
|
||||
if right.kind == .array && infix_expr.op == .key_in {
|
||||
return table.bool_type
|
||||
}
|
||||
// if !c.table.check(&infix_expr.right_type, &infix_expr.right_type) {
|
||||
// c.error('infix expr: cannot use `$infix_expr.right_type.name` as `$infix_expr.left_type.name`', infix_expr.pos)
|
||||
c.error('infix expr: cannot use `$right.name` (right) as `$left.name`', infix_expr.pos)
|
||||
|
|
|
@ -395,6 +395,11 @@ pub fn (t &Table) check(got, expected Type) bool {
|
|||
if exp_type_sym.name == 'array' || got_type_sym.name == 'array' {
|
||||
return true
|
||||
}
|
||||
// TODO
|
||||
// accept [] when an expected type is an array
|
||||
if got_type_sym.kind == .array && got_type_sym.name == 'array_void' && exp_type_sym.kind == .array {
|
||||
return true
|
||||
}
|
||||
if got_idx != exp_idx {
|
||||
// && got.typ.name != expected.typ.name*/
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue