stage1 支持函数指针

This commit is contained in:
zzy committed 2026-09-17 20:13:24 +08:00
1 parent 73c9a40abd
commit 70ac7380e9
4 files changed
+36 -1

No files matched your search

+10
View File
@@ -1775,6 +1775,16 @@ static spl_lang_type_id_t sema_infer(spl_sema_t *sema, spl_ast_node_ref_t ref) {
return bt;
}
case SPL_UNARY_OP_ADDRESS: {
spl_ast_node_t *operand = spl_ast_node(sema->ast, n->unary.operand);
if (operand && operand->kind == SPL_AST_EXPR_IDENT) {
spl_def_node_t *def = spl_def_node(sema->type, operand->resolved_def_id);
if (def && def->kind == SPL_DEF_FN) {
spl_diag_error(sema->diag, SPL_DIAG_KIND_TYPE_MISMATCH, &n->dbg,
"cannot take address of a function: the function name "
"itself is a function pointer");
return 0;
}
}
spl_lang_type_id_t p = spl_lang_make_ptr(sema->type, op);
n->resolved_lang_tid = p;
return p;