From eb7d55e4fa46b3781d59025d2e53c496444868e4 Mon Sep 17 00:00:00 2001 From: spookydonut Date: Sat, 10 Oct 2020 17:03:43 +0800 Subject: [PATCH] can be builtin --- src/dreamchecker/lib.rs | 32 +++++++++++++---------- src/dreamchecker/tests/directive_tests.rs | 16 ++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/dreamchecker/lib.rs b/src/dreamchecker/lib.rs index 21c7565e..ceacbaf3 100644 --- a/src/dreamchecker/lib.rs +++ b/src/dreamchecker/lib.rs @@ -402,17 +402,19 @@ struct ProcDirective<'o> { can_be_disabled: bool, set_at_definition: bool, can_be_global: bool, + can_be_builtin: bool, directive_string: &'static str, } impl<'o> ProcDirective<'o> { - pub fn new(directive_string: &'static str, can_be_disabled: bool, set_at_definition: bool, can_be_global: bool) -> ProcDirective<'o> { + pub fn new(directive_string: &'static str, can_be_disabled: bool, set_at_definition: bool, can_be_global: bool, can_be_builtin: bool) -> ProcDirective<'o> { ProcDirective { directive: Default::default(), directive_string, can_be_disabled, set_at_definition, can_be_global, + can_be_builtin, } } @@ -584,14 +586,14 @@ impl<'o> AnalyzeObjectTree<'o> { context, objtree, return_type, - must_call_parent: ProcDirective::new("SpacemanDMM_should_call_parent", true, false, false), - must_not_override: ProcDirective::new("SpacemanDMM_should_not_override", false, false, false), - private: ProcDirective::new("SpacemanDMM_private_proc", false, true, false), - protected: ProcDirective::new("SpacemanDMM_protected_proc", false, true, false), - must_not_sleep: ProcDirective::new("SpacemanDMM_should_not_sleep", false, true, true), - sleep_exempt: ProcDirective::new("SpacemanDMM_allowed_to_sleep", false, true, true), - must_be_pure: ProcDirective::new("SpacemanDMM_should_be_pure", false, true, true), - can_be_redefined: ProcDirective::new("SpacemanDMM_can_be_redefined", false, false, false), + must_call_parent: ProcDirective::new("SpacemanDMM_should_call_parent", true, false, false, true), + must_not_override: ProcDirective::new("SpacemanDMM_should_not_override", false, false, false, false), + private: ProcDirective::new("SpacemanDMM_private_proc", false, true, false, false), + protected: ProcDirective::new("SpacemanDMM_protected_proc", false, true, false, false), + must_not_sleep: ProcDirective::new("SpacemanDMM_should_not_sleep", false, true, true, true), + sleep_exempt: ProcDirective::new("SpacemanDMM_allowed_to_sleep", false, true, true, true), + must_be_pure: ProcDirective::new("SpacemanDMM_should_be_pure", false, true, true, true), + can_be_redefined: ProcDirective::new("SpacemanDMM_can_be_redefined", false, false, false, false), used_kwargs: Default::default(), call_tree: Default::default(), sleeping_procs: Default::default(), @@ -632,11 +634,13 @@ impl<'o> AnalyzeObjectTree<'o> { if procdirective.set_at_definition { if let Some(procdef) = &mut proc.get_declaration() { - if procdef.location != proc.get().location { - error(location, format!("Can't define procs {} outside their initial definition", directive)) - .set_severity(Severity::Warning) - .register(self.context); - return + if !(procdef.location.is_builtins() && procdirective.can_be_builtin) { + if procdef.location != proc.get().location { + error(location, format!("Can't define procs {} outside their initial definition", directive)) + .set_severity(Severity::Warning) + .register(self.context); + return + } } } } diff --git a/src/dreamchecker/tests/directive_tests.rs b/src/dreamchecker/tests/directive_tests.rs index a9570866..cd0b4efa 100644 --- a/src/dreamchecker/tests/directive_tests.rs +++ b/src/dreamchecker/tests/directive_tests.rs @@ -108,3 +108,19 @@ fn no_can_be_redefined() { "##.trim(); check_errors_match(code, NO_CAN_BE_REDEFINED_ERRORS); } + +pub const BUILT_IN_SLEEP: &[(u32, u16, &str)] = &[ + (4, 17, "/mob/living/proc/Move sets SpacemanDMM_should_not_sleep but calls blocking built-in(s)"), +]; + +#[test] +fn built_in_sleep() { + let code = r##" +/mob/Move() + set SpacemanDMM_should_not_sleep = TRUE + +/mob/living/Move() + sleep(1) +"##.trim(); + check_errors_match(code, BUILT_IN_SLEEP); +}