feat(contract): Phase 2 渐进式契约层 —— 契约表提取 + 四边界校验 + marqdo check 防漂移(T2.1–T2.5)
- src/contract.rs: 类型词汇(渐进标注)、参数/返回/字段三形状契约表解析、合并、四边界校验诊断 - src/parse/mod.rs: extract_function_contract —— 位置+形状双重判定,在升参推断之前提取; 绑定表/普通文档表绝不吃(P1 零回归),契约表从 body 移除(元数据永不执行) - src/interp.rs: 四边界校验 —— 调用实参(3 条调用路径)/返回/表绑定/字段访问 - src/check.rs + marqdo check [--json]: 漂移双向互查、未知类型名(附建议)、错位契约 - src/load.rs: label_error 保留结构化诊断(错误出口唯一,不拍平成字符串) - T2.4: 全部契约诊断带 doc_anchor/doc_quote/contract_ref - tests/contracts.rs 12 例全绿;全量回归零失败(含 262 gold) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
97fda7aa10
commit
7a449c40b1
17 files changed
+1586
-6
No files matched your search
+16
-3
@@ -252,6 +252,20 @@ pub fn load_module_from_source(source: &str) -> Result<Module> {
|
||||
load_module_from_source_inner(source, "<memory>", &mut visited)
|
||||
}
|
||||
|
||||
/// 给错误打上文件标签,**保留**结构化诊断(错误出口唯一;AI/MLSP 面不许拍平成字符串)。
|
||||
/// 无结构的错误退回 `{label}: {e}` 文本。
|
||||
fn label_error(label: &str, e: anyhow::Error) -> anyhow::Error {
|
||||
match crate::diagnostics::Diagnostic::find(&e).cloned() {
|
||||
Some(mut d) => {
|
||||
if d.path.is_none() {
|
||||
d.path = Some(PathBuf::from(label));
|
||||
}
|
||||
d.into()
|
||||
}
|
||||
None => anyhow::anyhow!("{label}: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn load_module_from_source_inner(
|
||||
source: &str,
|
||||
label: &str,
|
||||
@@ -263,7 +277,7 @@ fn load_module_from_source_inner(
|
||||
}
|
||||
|
||||
let result = (|| {
|
||||
let mut module = parse_source(source).map_err(|e| anyhow::anyhow!("{label}: {e}"))?;
|
||||
let mut module = parse_source(source).map_err(|e| label_error(label, e))?;
|
||||
let imports = module.imports.clone();
|
||||
let mut import_modules = HashMap::new();
|
||||
for imp in imports {
|
||||
@@ -274,8 +288,7 @@ fn load_module_from_source_inner(
|
||||
import_modules.insert(imp.bind, dep);
|
||||
}
|
||||
module.import_modules = import_modules;
|
||||
crate::inherit::validate_inheritance(&module)
|
||||
.map_err(|e| anyhow::anyhow!("{label}: {e}"))?;
|
||||
crate::inherit::validate_inheritance(&module).map_err(|e| label_error(label, e))?;
|
||||
Ok(module)
|
||||
})();
|
||||
|
||||
|
||||
Reference in new issue
Block a user