analysis: ensure Get.name exists in enum

This commit is contained in:
Luna 2019-09-26 22:27:05 -03:00
parent 6543884366
commit 2cb328c3f9
2 changed files with 19 additions and 3 deletions

View file

@ -23,7 +23,7 @@ enum C {
} }
fn test_function() B { fn test_function() B {
return B.bluh; return B.b;
} }
fn multwo(num: i32, double_flag: bool) i32 { fn multwo(num: i32, double_flag: bool) i32 {

View file

@ -255,8 +255,24 @@ pub const TypeSolver = struct {
// struct field (on get.name) type and return it // struct field (on get.name) type and return it
.Struct => @panic("TODO analysis of struct"), .Struct => @panic("TODO analysis of struct"),
// TODO check if get.name exists in enum .Enum => |enum_identifier| {
.Enum => return global_typ, // 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 => { else => {
std.debug.warn( std.debug.warn(