diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-05 00:58:45 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-05 00:58:45 -0400 |
| commit | 355ad9532163f9513c01aa59333aed5363386022 (patch) | |
| tree | 4e7204809e489d9d014dc189065e62f7e1670a24 /src/typecheck.c | |
| parent | f0b1a0f227cb7545af9ec27fbb4742b8c2c03bcd (diff) | |
Fix remaining metamethods
Diffstat (limited to 'src/typecheck.c')
| -rw-r--r-- | src/typecheck.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/typecheck.c b/src/typecheck.c index 0291b748..e4176508 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -1060,6 +1060,11 @@ type_t *get_type(env_t *env, ast_t *ast) return Type(BoolType); } + if (type_eq(lhs_t, rhs_t)) { + binding_t *b = get_metamethod_binding(env, ast->tag, binop.lhs, binop.rhs, lhs_t); + if (b) return lhs_t; + } + if (lhs_t->tag == OptionalType) { if (rhs_t->tag == OptionalType) { type_t *result = most_complete_type(lhs_t, rhs_t); @@ -1096,6 +1101,11 @@ type_t *get_type(env_t *env, ast_t *ast) return Type(BoolType); } + if (type_eq(lhs_t, rhs_t)) { + binding_t *b = get_metamethod_binding(env, ast->tag, binop.lhs, binop.rhs, lhs_t); + if (b) return lhs_t; + } + // Bitwise AND: if ((is_numeric_type(lhs_t) || lhs_t->tag == BoolType) && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) @@ -1120,6 +1130,11 @@ type_t *get_type(env_t *env, ast_t *ast) return Type(BoolType); } + if (type_eq(lhs_t, rhs_t)) { + binding_t *b = get_metamethod_binding(env, ast->tag, binop.lhs, binop.rhs, lhs_t); + if (b) return lhs_t; + } + // Bitwise XOR: if ((is_numeric_type(lhs_t) || lhs_t->tag == BoolType) && (is_numeric_type(rhs_t) || rhs_t->tag == BoolType) @@ -1203,8 +1218,8 @@ type_t *get_type(env_t *env, ast_t *ast) return lhs_t; } } - } else if (ast->tag == Divide && is_numeric_type(rhs_t)) { - binding_t *b = get_namespace_binding(env, binop.lhs, "divided_by"); + } else if ((ast->tag == Divide || ast->tag == Mod || ast->tag == Mod1) && is_numeric_type(rhs_t)) { + binding_t *b = get_namespace_binding(env, binop.lhs, binop_method_name(ast->tag)); if (b && b->type->tag == FunctionType) { auto fn = Match(b->type, FunctionType); if (type_eq(fn->ret, lhs_t)) { |
