!58 fix: 省略模块函数调用前缀,语义分析依然判定函数存在

Merge pull request !58 from zhangxun/bugfix/module-function-call-prefix
This commit is contained in:
Luke 2025-08-04 09:00:21 +00:00 committed by Gitee
commit e51ba01962
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -80,35 +80,7 @@ public class CallExpressionAnalyzer implements ExpressionAnalyzer<CallExpression
// 查找目标函数签名先在当前模块/显式模块查找
FunctionType ft = target.getFunctions().get(functionName);
// 如果当前模块未找到再自动遍历所有已导入模块寻找唯一同名函数
if (ft == null && target == mi) {
ModuleInfo foundModule = null;
FunctionType foundType = null;
for (String importName : mi.getImports()) {
ModuleInfo imported = ctx.getModules().get(importName);
if (imported == null) continue;
FunctionType candidate = imported.getFunctions().get(functionName);
if (candidate != null) {
if (foundModule != null) {
// 多个导入模块含有同名函数二义性报错
ctx.getErrors().add(new SemanticError(callee,
"函数调用不明确: " + functionName +
" 同时存在于模块 " + foundModule.getName() +
"" + imported.getName()));
ctx.log("错误: 函数调用不明确 " + functionName);
return BuiltinType.INT;
}
foundModule = imported;
foundType = candidate;
}
}
if (foundType != null) {
target = foundModule;
ft = foundType;
}
}
// 最终未找到则报错
// 未找到则报错
if (ft == null) {
ctx.getErrors().add(new SemanticError(callee,
"函数未定义: " + functionName));