checker: check ! operator
parent
718819eb7a
commit
831be43740
|
@ -319,18 +319,6 @@ mut:
|
|||
right_type table.Type
|
||||
}
|
||||
|
||||
/*
|
||||
// renamed to PrefixExpr
|
||||
pub struct UnaryExpr {
|
||||
pub:
|
||||
// tok_kind token.Kind
|
||||
// op BinaryOp
|
||||
op token.Kind
|
||||
left Expr
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
pub struct PostfixExpr {
|
||||
pub:
|
||||
op token.Kind
|
||||
|
@ -342,6 +330,7 @@ pub struct PrefixExpr {
|
|||
pub:
|
||||
op token.Kind
|
||||
right Expr
|
||||
pos token.Position
|
||||
}
|
||||
|
||||
pub struct IndexExpr {
|
||||
|
@ -528,9 +517,9 @@ pub struct DeferStmt {
|
|||
pub:
|
||||
stmts []Stmt
|
||||
mut:
|
||||
// TODO: handle this differently
|
||||
// v1 excludes non current os ifdefs so
|
||||
// the defer's never get added in the first place
|
||||
// TODO: handle this differently
|
||||
// v1 excludes non current os ifdefs so
|
||||
// the defer's never get added in the first place
|
||||
ifdef string
|
||||
}
|
||||
|
||||
|
|
|
@ -746,6 +746,9 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
|||
if it.op == .mul && table.type_is_ptr(right_type) {
|
||||
return table.type_deref(right_type)
|
||||
}
|
||||
if it.op == .not && right_type != table.bool_type_idx {
|
||||
c.error('! operator can only be used with bool types', it.pos)
|
||||
}
|
||||
return right_type
|
||||
}
|
||||
ast.None {
|
||||
|
|
|
@ -70,7 +70,8 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
|
|||
scanner: scanner.new_scanner_file(path, comments_mode)
|
||||
table: table
|
||||
file_name: path
|
||||
pref: pref //&pref.Preferences{}
|
||||
pref: pref // &pref.Preferences{}
|
||||
|
||||
scope: &ast.Scope{
|
||||
start_pos: 0
|
||||
parent: 0
|
||||
|
@ -904,6 +905,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
|||
}
|
||||
|
||||
fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
||||
pos := p.tok.position()
|
||||
op := p.tok.kind
|
||||
if op == .amp {
|
||||
p.is_amp = true
|
||||
|
@ -914,6 +916,7 @@ fn (p mut Parser) prefix_expr() ast.PrefixExpr {
|
|||
return ast.PrefixExpr{
|
||||
op: op
|
||||
right: right
|
||||
pos: pos
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue