mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
parent
8868696017
commit
dabc08b6ee
2 changed files with 26 additions and 1 deletions
|
@ -781,7 +781,12 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
|
|||
if g.pref.translated && node.typ.is_number() {
|
||||
g.writeln('_const_main__${val};')
|
||||
} else {
|
||||
g.writeln('${g.styp(node.typ)}__${val};')
|
||||
node_sym := g.table.sym(node.typ)
|
||||
if node_sym.info is ast.Alias {
|
||||
g.writeln('${g.styp(node_sym.info.parent_type)}__${val};')
|
||||
} else {
|
||||
g.writeln('${g.styp(node.typ)}__${val};')
|
||||
}
|
||||
}
|
||||
enum_attrs := sym.info.attrs[val]
|
||||
if enum_attrs.len == 0 {
|
||||
|
|
|
@ -5,6 +5,8 @@ enum CharacterGroup {
|
|||
special
|
||||
}
|
||||
|
||||
type AnotherCharGroup = CharacterGroup
|
||||
|
||||
fn (self CharacterGroup) value() string {
|
||||
return match self {
|
||||
.chars { 'first' }
|
||||
|
@ -33,3 +35,21 @@ fn test_main() {
|
|||
assert values == [CharacterGroup.chars, CharacterGroup.alphanumerics, CharacterGroup.numeric,
|
||||
CharacterGroup.special]
|
||||
}
|
||||
|
||||
fn test_alias_enum() {
|
||||
mut values := []EnumData{}
|
||||
$for entry in AnotherCharGroup.values {
|
||||
values << entry
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue