checker: check bool and string ops

pull/4397/head
Alexander Medvednikov 2020-04-14 04:12:24 +02:00
parent 885612afea
commit bbc35b1179
2 changed files with 9 additions and 1 deletions

View File

@ -215,6 +215,15 @@ pub fn (c mut Checker) infix_expr(infix_expr mut ast.InfixExpr) table.Type {
c.error('infix expr: cannot use `$right.name` (right expression) as `$left.name`',
infix_expr.pos)
}
if left_type == table.bool_type && infix_expr.op !in [.eq, .ne, .logical_or, .and] {
c.error('bool types only have the following operators defined: `==`, `!=`, `||`, and `&&`',
infix_expr.pos)
} else if left_type == table.string_type && !(infix_expr.op in [.plus, .eq, .ne, .lt, .gt, .le,
.ge]) {
// TODO broken !in
c.error('string types only have the following operators defined: `==`, `!=`, `<`, `>`, `<=`, `>=`, and `&&`',
infix_expr.pos)
}
if infix_expr.op.is_relational() {
return table.bool_type
}

View File

@ -250,7 +250,6 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
if g.is_json_fn {
g.write('json__json_print(')
g.gen_json_for_type(node.args[0].typ)
println('XAXAXAX')
json_type_str = g.table.get_type_symbol(node.args[0].typ).name
}
if node.is_c {