File tree Expand file tree Collapse file tree 4 files changed +35
-3
lines changed Expand file tree Collapse file tree 4 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -678,6 +678,16 @@ pub fn (t &Table) unalias_num_type(typ Type) Type {
678
678
return typ
679
679
}
680
680
681
+ [inline ]
682
+ pub fn (t &Table) unaliased_type (typ Type) Type {
683
+ sym := t.sym (typ)
684
+ if sym.kind == .alias {
685
+ pt := (sym.info as Alias ).parent_type
686
+ return pt
687
+ }
688
+ return typ
689
+ }
690
+
681
691
fn (mut t Table) rewrite_already_registered_symbol (typ TypeSymbol, existing_idx int ) int {
682
692
existing_symbol := t.type_symbols[existing_idx]
683
693
if existing_symbol.kind == .placeholder {
Original file line number Diff line number Diff line change @@ -4428,12 +4428,13 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
4428
4428
typ = array_info.elem_type
4429
4429
typ_sym = c.table.sym (typ)
4430
4430
}
4431
- if typ_sym.kind != .enum_ && ! c.pref.translated {
4431
+ fsym := c.table.final_sym (typ)
4432
+ if fsym.kind != .enum_ && ! c.pref.translated {
4432
4433
// TODO in C int fields can be compared to enums, need to handle that in C2V
4433
4434
c.error ('expected type is not an enum (`$typ_sym.name `)' , node.pos)
4434
4435
return ast.void_type
4435
4436
}
4436
- if typ_sym .info ! is ast.Enum {
4437
+ if fsym .info ! is ast.Enum {
4437
4438
c.error ('not an enum' , node.pos)
4438
4439
return ast.void_type
4439
4440
}
Original file line number Diff line number Diff line change @@ -3153,7 +3153,7 @@ fn (mut g Gen) expr(node ast.Expr) {
3153
3153
ast.EnumVal {
3154
3154
// g.write('${it.mod}${it.enum_name}_$it.val')
3155
3155
// g.enum_expr(node)
3156
- styp := g.typ (node.typ)
3156
+ styp := g.typ (g.table. unaliased_type ( node.typ) )
3157
3157
g.write ('${styp} __$node.val ' )
3158
3158
}
3159
3159
ast.FloatLiteral {
Original file line number Diff line number Diff line change
1
+ enum MyEnum {
2
+ something
3
+ another
4
+ third
5
+ }
6
+
7
+ type MyEnumAlias = MyEnum
8
+
9
+ fn test_enum_aliases () {
10
+ x := MyEnum.something
11
+ dump (x)
12
+ a := MyEnumAlias.something
13
+ dump (a)
14
+ assert x == a
15
+ //
16
+ dump (MyEnum.third)
17
+ dump (MyEnumAlias.third)
18
+ dump (int (MyEnum.third))
19
+ dump (int (MyEnumAlias.third))
20
+ assert MyEnum.third == MyEnumAlias.third
21
+ }
You can’t perform that action at this time.
0 commit comments