fix(tyck): func register, ret type recover

This commit is contained in:
2025-11-06 03:01:05 +08:00
parent cc34f59a4d
commit c850ceb3b6
3 changed files with 8 additions and 6 deletions

View File

@@ -82,6 +82,7 @@ pub fn Context::exit_scope(self : Context) -> Unit {
}
///|
#deprecated
pub fn Context::set_current_func_ret_ty(self : Context, ty : TypeKind) -> Unit {
self.current_func_ret_ty = Some(ty)
}
@@ -115,7 +116,9 @@ pub fn Context::check_program(
}
// 收集顶层函数声明
for name, func in program.top_functions {
self.func_types.set(name, self.check_top_function_type_decl(func))
let func_type = self.check_top_function_type_decl(func)
self.func_types.set(name, func_type)
self.type_env.set(name, { kind: func_type, mutable: false })
}
// 补充内建函数类型
self.add_intrinsic_functions()

View File

@@ -26,8 +26,9 @@ pub fn Context::check_local_function(
let func_type = Function(param_list.map(p => p.1.kind), ret_type)
self.type_env.set(func.id, { kind: func_type, mutable: false })
//
self.enter_scope()
let parent_func_ret_ty = self.current_func_ret_ty
self.current_func_ret_ty = Some(ret_type)
self.enter_scope()
//
for param in param_list {
let (param_name, param_type) = param
@@ -42,6 +43,7 @@ pub fn Context::check_local_function(
}
//
self.exit_scope()
self.current_func_ret_ty = parent_func_ret_ty
//
{
fname: func.id,

View File

@@ -31,10 +31,6 @@ pub fn Context::check_top_function_body(
guard self.func_types.get(func.id) is Some(Function(param_types, ret_ty)) else {
raise TypeCheckError("Function type for '\{func.id}' not found.")
}
self.type_env.set(func.id, {
kind: Function(param_types, ret_ty),
mutable: false,
})
self.enter_scope()
self.current_func_ret_ty = Some(ret_ty)
for i in 0..<param_names.length() {
@@ -48,6 +44,7 @@ pub fn Context::check_top_function_body(
)
}
self.exit_scope()
self.current_func_ret_ty = None
if func.user_defined_type is Some(UserDefined(udt)) {
self.type_env.local_.remove("$Generic$\{udt}")
}