feat(frontend): cross-module call validation and builtin namespace inference

- calls: validate_program runs after a whole project is loaded and checks
  qualified calls through explicit import aliases against the imported module's
  signatures (missing function, missing/unknown arguments), plus qualified
  builtin calls such as math.eval; local calls stay checked by
  validate_module so diagnostics are not duplicated.
- infer: `math.eval(...)` / `foreign.call(...)` callee namespaces are builtin
  namespaces, not free variable reads, so they no longer become inferred
  parameters or unknown-variable errors. Explicit signatures behave likewise.
This commit is contained in:
cflmy committed 2026-11-20 10:43:59 +08:00
1 parent 3f8dce013b
commit d54fda9e78
2 files changed
+109 -6

No files matched your search

+14 -2
View File
@@ -139,9 +139,21 @@ impl<'a> Analyzer<'a> {
self.read_expr(right, state);
}
Expr::Call { callee, args, .. } => {
// A bare identifier callee names a function, not a variable.
// A callee identifier names a function; a `ns.name` callee is a
// builtin namespace (math.eval) or an imported module alias.
// Neither is a variable read.
match callee.as_ref() {
Expr::Ident(_) => {}
Expr::Member { base, name, .. } => {
let is_builtin_namespace = matches!(
base.as_ref(),
Expr::Ident(ident)
if marqdo_ir::builtins::find(&format!("{}.{name}", ident.name)).is_some()
);
if !is_builtin_namespace {
self.read_expr(base, state);
}
}
other => self.read_expr(other, state),
}
for Arg { value, .. } in args {
@@ -295,7 +307,7 @@ pub fn infer(
#[cfg(test)]
mod tests {
use super::*;
use marqdo_expression::{parse_expression, parse_statement};
use marqdo_expression::parse_expression;
fn assign(name: &str, value: &str) -> Stmt {
Stmt::Assign {