Skip to content

Commit d52b9ab

Browse files
committed
Close #265
1 parent da35c85 commit d52b9ab

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

crates/emmylua_code_analysis/src/compilation/test/closure_return_test.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(test)]
22
mod test {
3-
use crate::VirtualWorkspace;
3+
use crate::{DiagnosticCode, VirtualWorkspace};
44

55
#[test]
66
fn test_flow() {
@@ -26,4 +26,24 @@ mod test {
2626
let expected = ws.ty("string[]");
2727
assert_eq!(ty, expected);
2828
}
29+
30+
#[test]
31+
fn test_issue_265() {
32+
let mut ws = VirtualWorkspace::new();
33+
34+
assert!(ws.check_code_for(
35+
DiagnosticCode::ReturnTypeMismatch,
36+
r#"
37+
local function bar()
38+
return ''
39+
end
40+
41+
--- @return integer
42+
function foo()
43+
return bar() --[[@as integer]]
44+
end
45+
46+
"#,
47+
));
48+
}
2949
}

crates/emmylua_code_analysis/src/compilation/test/flow.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,20 @@ end
305305
fn test_issue_266() {
306306
let mut ws = VirtualWorkspace::new();
307307

308-
assert!(ws.check_code_for(DiagnosticCode::AssignTypeMismatch, r#"
308+
assert!(ws.check_code_for(
309+
DiagnosticCode::AssignTypeMismatch,
310+
r#"
309311
--- @return string
310312
function baz() end
311313
312314
local a
313315
a = baz() -- a has type nil but should be string
314316
d = a
315-
"#));
317+
"#
318+
));
316319

317320
let d = ws.expr_ty("d");
318321
let d_desc = ws.humanize_type(d);
319322
assert_eq!(d_desc, "string");
320323
}
321-
322324
}

0 commit comments

Comments
 (0)