checker: allow voidptr arithmetic in translated code
parent
f4586b1577
commit
547265dd44
|
@ -1087,7 +1087,7 @@ pub mut:
|
||||||
expr_type Type // from type
|
expr_type Type // from type
|
||||||
}
|
}
|
||||||
|
|
||||||
// an enum value, like OS.macos or .macos
|
// An enum value, like OS.macos or .macos
|
||||||
pub struct EnumVal {
|
pub struct EnumVal {
|
||||||
pub:
|
pub:
|
||||||
enum_name string
|
enum_name string
|
||||||
|
|
|
@ -589,7 +589,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||||
if !c.inside_unsafe && !node.left.is_auto_deref_var() && !node.right.is_auto_deref_var() {
|
if !c.inside_unsafe && !node.left.is_auto_deref_var() && !node.right.is_auto_deref_var() {
|
||||||
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', left_right_pos)
|
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', left_right_pos)
|
||||||
}
|
}
|
||||||
if left_type == ast.voidptr_type {
|
if left_type == ast.voidptr_type && !c.pref.translated {
|
||||||
c.error('`$node.op` cannot be used with `voidptr`', left_pos)
|
c.error('`$node.op` cannot be used with `voidptr`', left_pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3962,6 +3962,8 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
|
||||||
// with this value.
|
// with this value.
|
||||||
pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
|
pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
|
||||||
mut typ_idx := if node.enum_name == '' {
|
mut typ_idx := if node.enum_name == '' {
|
||||||
|
// Get the type of the enum without enum name by looking at the expected type.
|
||||||
|
// e.g. `set_color(.green)`, V knows that `Green` is the expected type.
|
||||||
if c.expected_type == ast.void_type && c.expected_expr_type != ast.void_type {
|
if c.expected_type == ast.void_type && c.expected_expr_type != ast.void_type {
|
||||||
c.expected_expr_type.idx()
|
c.expected_expr_type.idx()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5353,7 +5353,8 @@ fn (mut g Gen) enum_val(node ast.EnumVal) {
|
||||||
// && g.inside_switch
|
// && g.inside_switch
|
||||||
if g.pref.translated && node.typ.is_number() {
|
if g.pref.translated && node.typ.is_number() {
|
||||||
// Mostly in translated code, when C enums are used as ints in switches
|
// Mostly in translated code, when C enums are used as ints in switches
|
||||||
g.write('/*enum val is_number $node.mod styp=$styp*/_const_main__$node.val')
|
sym := g.table.sym(node.typ)
|
||||||
|
g.write('/* $node enum val is_number $node.mod styp=$styp sym=$sym*/_const_main__$node.val')
|
||||||
} else {
|
} else {
|
||||||
g.write('${styp}__$node.val')
|
g.write('${styp}__$node.val')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue