Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 4fc798d

Browse files
committed
Handle member access in struct with union as const arg
Closes #228
1 parent 74da43f commit 4fc798d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/Translator.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ fn transRecordDecl(t: *Translator, scope: *Scope, record_qt: QualType) Error!voi
557557
field_name = try std.fmt.allocPrint(t.arena, "unnamed_{d}", .{unnamed_field_count});
558558
unnamed_field_count += 1;
559559
try t.anonymous_record_field_names.put(t.gpa, .{
560-
.parent = base.qt,
560+
.parent = base.qt.unqualified(),
561561
.field = field.qt,
562562
}, field_name);
563563
}
@@ -3066,7 +3066,7 @@ fn transMemberAccess(
30663066
const record = base_info.getRecord(t.comp).?;
30673067
const field = record.fields[member_access.member_index];
30683068
const field_name = if (field.name_tok == 0) t.anonymous_record_field_names.get(.{
3069-
.parent = base_info.base(t.comp).qt,
3069+
.parent = base_info.base(t.comp).qt.unqualified(),
30703070
.field = field.qt,
30713071
}).? else field.name.lookup(t.comp);
30723072
const base_node = opt_base orelse try t.transExpr(scope, member_access.base, .used);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#define SUFFIXED(x) x##_suffix
2+
3+
struct my_struct {
4+
union {
5+
int SUFFIXED(internal);
6+
double d;
7+
};
8+
};
9+
10+
int my_func(const struct my_struct* s) {
11+
return s->SUFFIXED(internal);
12+
}

0 commit comments

Comments
 (0)