diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 06fb9a1bf7..1f059fd2cb 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1087,7 +1087,7 @@ pub mut: 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: enum_name string diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 3bdbf50278..8dd4635814 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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() { 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) } } @@ -3962,6 +3962,8 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type { // with this value. pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type { 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 { c.expected_expr_type.idx() } else { diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index a03406716c..c1d25eee07 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5353,7 +5353,8 @@ fn (mut g Gen) enum_val(node ast.EnumVal) { // && g.inside_switch if g.pref.translated && node.typ.is_number() { // 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 { g.write('${styp}__$node.val') }