mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check ! operator
This commit is contained in:
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 {
|
||||
|
@ -52,7 +52,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||
pref: &pref.Preferences{}
|
||||
scope: scope
|
||||
// scope: &ast.Scope{start_pos: 0, parent: 0}
|
||||
|
||||
|
||||
}
|
||||
p.init_parse_fns()
|
||||
p.read_first_token()
|
||||
@ -70,13 +70,14 @@ 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
|
||||
}
|
||||
// comments_mode: comments_mode
|
||||
|
||||
|
||||
}
|
||||
p.read_first_token()
|
||||
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
|
||||
@ -687,7 +688,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||
p.expr_mod = ''
|
||||
return ast.EnumVal{
|
||||
enum_name: enum_name // lp.prepend_mod(enum_name)
|
||||
|
||||
|
||||
val: val
|
||||
pos: p.tok.position()
|
||||
mod: mod
|
||||
@ -777,7 +778,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
||||
node = ast.SizeOf{
|
||||
typ: sizeof_type
|
||||
// type_name: type_name
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
.key_typeof {
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -1045,7 +1048,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
|
||||
left: left
|
||||
right: right
|
||||
// right_type: typ
|
||||
|
||||
|
||||
op: op
|
||||
pos: pos
|
||||
}
|
||||
@ -1450,7 +1453,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
|
||||
fields << ast.Field{
|
||||
name: name
|
||||
// typ: typ
|
||||
|
||||
|
||||
}
|
||||
exprs << expr
|
||||
// TODO: once consts are fixed reg here & update in checker
|
||||
|
Loading…
Reference in New Issue
Block a user