mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
do not allow casting bool to int
This commit is contained in:
parent
3a6ccf7f31
commit
1bd8c465d3
@ -67,11 +67,11 @@ pub fn (aa mut Automaton) update() {
|
||||
)
|
||||
cell := aa.field.get(x,y)
|
||||
v := if cell == 1 {
|
||||
int(moore_sum in [2, 3])
|
||||
moore_sum in [2, 3]
|
||||
} else {
|
||||
int(moore_sum == 3)
|
||||
moore_sum == 3
|
||||
}
|
||||
aa.new_field.set(x,y, v )
|
||||
aa.new_field.set(x,y, if v { 1 } else { 0 })
|
||||
}
|
||||
}
|
||||
mut tmp := aa.field
|
||||
|
@ -552,6 +552,10 @@ fn (p mut Parser) cast(typ string) {
|
||||
if expr_typ == 'string' {
|
||||
p.error('cannot cast `$expr_typ` to `$typ`')
|
||||
}
|
||||
// Nothing can be cast to bool
|
||||
if expr_typ == 'bool' {
|
||||
p.error('cannot cast `bool` to `$typ`')
|
||||
}
|
||||
p.cgen.set_placeholder(pos, '($typ)(')
|
||||
}
|
||||
p.check(.rpar)
|
||||
|
@ -102,7 +102,7 @@ pub fn (p mut Params) put_string(name string, s string) {
|
||||
}
|
||||
|
||||
pub fn (p mut Params) put_bool(name string, val bool) {
|
||||
p.put_custom(name, "bool", int(val))
|
||||
p.put_custom(name, "bool", if val { 1 } else { 0 })
|
||||
}
|
||||
|
||||
pub fn (p mut Params) put_custom(name string, typ string, data voidptr) {
|
||||
|
Loading…
Reference in New Issue
Block a user