From 3c9be17701eb7abe375f04db2ee7bc4452834c3b Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Tue, 15 Sep 2020 19:51:19 -0700 Subject: [PATCH] Fix errors if /client/parent_type is left at the default --- src/dreammaker/constants.rs | 2 ++ src/dreammaker/objtree.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dreammaker/constants.rs b/src/dreammaker/constants.rs index 41a16640..f6c3c260 100644 --- a/src/dreammaker/constants.rs +++ b/src/dreammaker/constants.rs @@ -130,6 +130,8 @@ impl Constant { // ------------------------------------------------------------------------ // Constructors + pub const EMPTY_STRING: &'static Constant = &Constant::String(String::new()); + pub fn null() -> &'static Constant { static NULL: Constant = Constant::Null(None); &NULL diff --git a/src/dreammaker/objtree.rs b/src/dreammaker/objtree.rs index f7195996..09c57a77 100644 --- a/src/dreammaker/objtree.rs +++ b/src/dreammaker/objtree.rs @@ -758,7 +758,7 @@ impl ObjectTree { fn assign_parent_types(&mut self, context: &Context) { for (path, &type_idx) in self.types.iter() { - let mut location = self.graph[type_idx.index()].location; + let mut location = self[type_idx].location; let idx = if path == "/datum" || path == "/list" || path == "/savefile" || path == "/world" { // These types have no parent and cannot have one added. In the official compiler: // - setting list or savefile/parent_type is denied with the same error as setting something's parent type to them; @@ -807,8 +807,11 @@ impl ObjectTree { } Err(e) => Err(e), } + } else if path == "/client" { + Ok(Constant::EMPTY_STRING) } else { - Err(DMError::new(location, "bad parent_type: no value")) + // A weird situation which should not happen. + Err(DMError::new(location, format!("missing {}/parent_type", path))) }; match constant { @@ -824,7 +827,7 @@ impl ObjectTree { parent_type = &parent_type_buf; } Ok(other) => { - context.register_error(DMError::new(location, format!("bad parent_type: {}", other))); + context.register_error(DMError::new(location, format!("value of {}/parent_type must be a string or typepath, got {}", path, other))); } Err(e) => { context.register_error(e);