kcl
kcl copied to clipboard
[Bug] The loader will return the incorrect number of scopes when there is a schema present
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Write the following unit test in the loader crate
#[macro_export]
macro_rules! load_package_scopes_snapshot {
($name:ident, $src:expr) => {
#[test]
fn $name() {
let p = load_packages(&LoadPackageOptions {
paths: vec!["test.k".to_string()],
load_opts: Some(LoadProgramOptions {
k_code_list: vec![$src.to_string()],
..Default::default()
}),
load_builtin: false,
..Default::default()
})
.unwrap();
insta::assert_snapshot!(format!("{:#?}", p.scopes.get(&p.pkg_scope_map["__main__"]).unwrap().children));
}
};
}
load_package_scopes_snapshot! {schema_scope_0, r#"opt = option
schema Person:
name: str
age: int
p = Person {
name: "Alice"
age: 18
}
"#}
2. What did you expect to see? (Required)
The length of children is 2
3. What did you see instead (Required)
The length of children is 2
4. What is your KCL components version? (Required)
Version: 0.9.0-c020ab3eb4b9179219d6837a57f5d323
Platform: aarch64-apple-darwin
GitCommit: fdd797ac59b2b0a5259cafdf8850a0f6abbc2fce