aboutsummaryrefslogtreecommitdiff
path: root/src/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-23 13:28:48 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-23 13:28:48 -0500
commit0fa9a52090eb5d9ce88220c0134a8d2af6eb8d94 (patch)
tree87a3181238da384a94077f401b0ba49eb8eb1e7e /src/types.c
parent1c77d596b28ee45e0234cfa7c5f5679492f2178e (diff)
Accessing enum fields now gives an optional value instead of a boolean
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/types.c b/src/types.c
index 73c02807..51555560 100644
--- a/src/types.c
+++ b/src/types.c
@@ -633,7 +633,9 @@ type_t *get_field_type(type_t *t, const char *field_name) {
case EnumType: {
DeclareMatch(e, t, EnumType);
for (tag_t *tag = e->tags; tag; tag = tag->next) {
- if (streq(field_name, tag->name)) return Type(BoolType);
+ if (!streq(field_name, tag->name)) continue;
+ if (tag->type != NULL && Match(tag->type, StructType)->fields) return Type(OptionalType, tag->type);
+ else return Type(OptionalType, EMPTY_TYPE);
}
return NULL;
}