diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index c44b33b04d..c0479c343b 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -781,7 +781,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { if g.pref.translated && node.typ.is_number() { g.writeln('_const_main__${val};') } else { - node_sym := g.table.sym(node.typ) + node_sym := g.table.sym(g.unwrap_generic(node.typ)) if node_sym.info is ast.Alias { g.writeln('${g.styp(node_sym.info.parent_type)}__${val};') } else { diff --git a/vlib/v/tests/comptime/comptime_enum_values_test.v b/vlib/v/tests/comptime/comptime_enum_values_test.v index a652798bd3..2961d3ec7e 100644 --- a/vlib/v/tests/comptime/comptime_enum_values_test.v +++ b/vlib/v/tests/comptime/comptime_enum_values_test.v @@ -24,6 +24,14 @@ fn CharacterGroup.values() []CharacterGroup { return res } +fn do_generic[T](t T) []EnumData { + mut vals := []EnumData{} + $for value in T.values { + vals << value + } + return vals +} + fn test_main() { values := CharacterGroup.values() println('Char group values: ${values}') @@ -53,3 +61,19 @@ fn test_alias_enum() { assert values[3].value == int(CharacterGroup.special) assert values[3].name == CharacterGroup.special.str() } + +fn test_generic_alias_enum() { + values := do_generic(AnotherCharGroup.chars) + + assert values[0].value == int(CharacterGroup.chars) + assert values[0].name == CharacterGroup.chars.str() + + assert values[1].value == int(CharacterGroup.alphanumerics) + assert values[1].name == CharacterGroup.alphanumerics.str() + + assert values[2].value == int(CharacterGroup.numeric) + assert values[2].name == CharacterGroup.numeric.str() + + assert values[3].value == int(CharacterGroup.special) + assert values[3].name == CharacterGroup.special.str() +}