mirror of
https://github.com/Dummi26/mers.git
synced 2025-10-28 10:46:15 +01:00
This commit is contained in:
parent
ffcd95c72d
commit
688281961d
@ -15,7 +15,7 @@ default = ["colored-output"]
|
||||
colored-output = ["mers_lib/ecolor-term", "mers_lib/pretty-print", "dep:colored"]
|
||||
|
||||
[dependencies]
|
||||
mers_lib = "0.9.23"
|
||||
mers_lib = "0.9.24"
|
||||
# mers_lib = { path = "../mers_lib" }
|
||||
clap = { version = "4.3.19", features = ["derive"] }
|
||||
colored = { version = "2.1.0", optional = true }
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mers_lib"
|
||||
version = "0.9.23"
|
||||
version = "0.9.24"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "library to use the mers language in other projects"
|
||||
|
||||
@ -24,18 +24,65 @@ impl MersStatement for Object {
|
||||
let print_is_part_of = init_to.types.len() > 1;
|
||||
let mut init_fields = HashMap::new();
|
||||
for t in init_to.types.iter() {
|
||||
if let Some(t) = t.as_any().downcast_ref::<ObjectT>() {
|
||||
for (field, t) in t.iter() {
|
||||
if let Some(ot) = t.as_any().downcast_ref::<ObjectT>() {
|
||||
let mut fields = self.fields.iter().map(|(t, _)| *t).collect::<Vec<_>>();
|
||||
fields.sort();
|
||||
for (field, t) in ot.iter() {
|
||||
if let Ok(i) = fields.binary_search(field) {
|
||||
fields.remove(i);
|
||||
}
|
||||
init_fields
|
||||
.entry(*field)
|
||||
.or_insert_with(Type::empty)
|
||||
.add_all(t);
|
||||
}
|
||||
if !fields.is_empty() {
|
||||
return Err(CheckError::new().msg(vec![
|
||||
("can't init an ".to_owned(), None),
|
||||
("object".to_owned(), Some(EColor::InitTo)),
|
||||
(" from type ".to_owned(), None),
|
||||
(t.simplified_as_string(info), Some(EColor::InitFrom)),
|
||||
if print_is_part_of {
|
||||
(", which is part of ".to_owned(), None)
|
||||
} else {
|
||||
(format!(""), None)
|
||||
},
|
||||
if print_is_part_of {
|
||||
(init_to.simplified_as_string(info), Some(EColor::InitFrom))
|
||||
} else {
|
||||
(format!(""), None)
|
||||
},
|
||||
(
|
||||
format!(" - missing fields {}", {
|
||||
let object_fields_rev =
|
||||
info.global.object_fields_rev.lock().unwrap();
|
||||
fields
|
||||
.iter()
|
||||
.map(|f| {
|
||||
object_fields_rev
|
||||
.get(*f)
|
||||
.map(|f| f.as_str())
|
||||
.unwrap_or("<unknown>")
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(i, f)| {
|
||||
if i == 0 {
|
||||
f.to_owned()
|
||||
} else {
|
||||
format!(", {f}")
|
||||
}
|
||||
})
|
||||
.collect::<String>()
|
||||
}),
|
||||
None,
|
||||
),
|
||||
]));
|
||||
}
|
||||
} else {
|
||||
return Err(CheckError::new().msg(vec![
|
||||
("can't init an ".to_owned(), None),
|
||||
("object".to_owned(), Some(EColor::InitTo)),
|
||||
(" with type ".to_owned(), None),
|
||||
(" from type ".to_owned(), None),
|
||||
(t.simplified_as_string(info), Some(EColor::InitFrom)),
|
||||
if print_is_part_of {
|
||||
(", which is part of ".to_owned(), None)
|
||||
@ -72,22 +119,7 @@ impl MersStatement for Object {
|
||||
} else if init_to_is_empty_type {
|
||||
Type::empty()
|
||||
} else {
|
||||
return Err(CheckError::new().msg(vec![
|
||||
("can't init an ".to_owned(), None),
|
||||
("object".to_owned(), Some(EColor::InitTo)),
|
||||
(" with type ".to_owned(), None),
|
||||
(
|
||||
init_to.as_ref().unwrap().simplified_as_string(info),
|
||||
Some(EColor::InitFrom),
|
||||
),
|
||||
(
|
||||
format!(
|
||||
" - field {} is missing",
|
||||
info.display_info().get_object_field_name(*field)
|
||||
),
|
||||
None,
|
||||
),
|
||||
]));
|
||||
unreachable!("type-checking earlier in check_custom() should prevent this")
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user