Skip to content

Commit 66c3c90

Browse files
authored
Fix "should not sleep" to catch world.Export and world.Import (#216)
Fixes #208.
1 parent f2dc9a4 commit 66c3c90

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/dreamchecker/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,13 @@ impl<'o, 's> AnalyzeProc<'o, 's> {
17021702
},
17031703

17041704
Term::Call(unscoped_name, args) => {
1705-
if unscoped_name == "sleep" || unscoped_name == "alert" || unscoped_name == "shell" || unscoped_name == "winexists" || unscoped_name == "winget" {
1706-
if self.inside_newcontext == 0 {
1705+
if self.inside_newcontext == 0 && matches!(unscoped_name.as_str(),
1706+
"sleep"
1707+
| "alert"
1708+
| "shell"
1709+
| "winexists"
1710+
| "winget") {
17071711
self.env.sleeping_procs.insert_violator(self.proc_ref, unscoped_name, location);
1708-
}
17091712
}
17101713
let src = self.ty;
17111714
if let Some(proc) = self.ty.get_proc(unscoped_name) {
@@ -1952,6 +1955,13 @@ impl<'o, 's> AnalyzeProc<'o, 's> {
19521955
.register(self.context);
19531956
}
19541957
}
1958+
if ty.get().path.as_str() == "/world" {
1959+
if self.inside_newcontext == 0 && matches!(name.as_str(),
1960+
"Import"
1961+
| "Export") {
1962+
self.env.sleeping_procs.insert_violator(self.proc_ref, format!("world.{}", name).as_str(), location);
1963+
}
1964+
}
19551965
self.visit_call(location, ty, proc, arguments, false, local_vars)
19561966
} else {
19571967
error(location, format!("undefined proc: {:?} on {}", name, ty))

src/dreamchecker/tests/directive_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ fn no_can_be_redefined() {
107107
return
108108
"##.trim();
109109
check_errors_match(code, NO_CAN_BE_REDEFINED_ERRORS);
110-
}
110+
}

src/dreamchecker/tests/sleep_pure_tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ fn sleep3() {
112112
]);
113113
}
114114

115+
pub const SLEEP_ERROR4: &[(u32, u16, &str)] = &[
116+
(1, 16, "/mob/proc/test1 sets SpacemanDMM_should_not_sleep but calls blocking built-in(s)"),
117+
];
118+
119+
#[test]
120+
fn sleep4() {
121+
let code = r##"
122+
/mob/proc/test1()
123+
set SpacemanDMM_should_not_sleep = TRUE
124+
world.Export()
125+
world.Import()
126+
"##.trim();
127+
check_errors_match(code, SLEEP_ERROR4);
128+
}
129+
115130
pub const PURE_ERRORS: &[(u32, u16, &str)] = &[
116131
(12, 16, "/mob/proc/test2 sets SpacemanDMM_should_be_pure but calls a /proc/impure that does impure operations"),
117132
];

0 commit comments

Comments
 (0)