use FnType instead of the tuple mess

This commit is contained in:
2026-03-17 16:27:39 +01:00
parent a3f480dc1d
commit 15a68a41d1
3 changed files with 74 additions and 54 deletions

View File

@@ -4,13 +4,11 @@
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use crate::{
analyzer::Analyzer,
analyzer::{Analyzer, Type},
parser::{Expr, Stmt},
tokenizer::{TokenType, ZernError, error},
};
type Type = String;
macro_rules! expect_type {
($expr_type:expr, $expected:expr, $loc:expr) => {
if $expected != "any" && $expr_type != "any" && $expr_type != $expected {
@@ -330,14 +328,15 @@ impl TypeChecker {
.functions
.contains_key(&callee_name.lexeme)
{
let params = self.analyzer.borrow().functions[&callee_name.lexeme].clone();
if let (_, Some(params)) = params {
let fn_type =
&self.analyzer.borrow().functions[&callee_name.lexeme].clone();
if let Some(params) = fn_type.params.clone() {
// its a function (defined/builtin/extern)
for (i, arg) in args.iter().enumerate() {
expect_type!(self.typecheck_expr(env, arg)?, params[i], paren.loc);
}
}
Ok(params.0)
Ok(fn_type.return_type.clone())
} else {
// its a variable containing function address
expect_type!(self.typecheck_expr(env, callee)?, "fnptr", paren.loc);