diff --git a/examples/hello.ry b/examples/hello.ry index f338ce4..34bcb18 100644 --- a/examples/hello.ry +++ b/examples/hello.ry @@ -23,7 +23,7 @@ enum C { } fn test_function() B { - return B.bluh; + return B.b; } fn multwo(num: i32, double_flag: bool) i32 { diff --git a/src/types.zig b/src/types.zig index 50ab2bb..c9ac686 100644 --- a/src/types.zig +++ b/src/types.zig @@ -255,8 +255,24 @@ pub const TypeSolver = struct { // struct field (on get.name) type and return it .Struct => @panic("TODO analysis of struct"), - // TODO check if get.name exists in enum - .Enum => return global_typ, + .Enum => |enum_identifier| { + // fetch an enum off symbol table, then we use the + // identifier map to ensure get.name exists in the enum + var map = ctx.symbol_table.get(enum_identifier).?.value.Enum; + const name = get.name.lexeme; + + var kv = map.get(name); + if (kv == null) { + self.doError( + "Field {} not found in enum {}", + name, + lexeme, + ); + return CompileError.TypeError; + } + + return global_typ; + }, else => { std.debug.warn(