Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
942 changes: 942 additions & 0 deletions crates/emmylua_code_analysis/src/compilation/test/flow.rs

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions crates/emmylua_code_analysis/src/compilation/test/pcall_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod test {
use crate::{DiagnosticCode, VirtualWorkspace};

const STACKED_PCALL_ALIAS_GUARDS: usize = 180;

#[test]
fn test_issue_263() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
Expand Down Expand Up @@ -141,4 +143,36 @@ mod test {
assert_eq!(ws.expr_ty("status"), ws.ty("boolean|string"));
assert_eq!(ws.expr_ty("payload"), ws.ty("integer|string"));
}

#[test]
fn test_pcall_stacked_alias_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
let repeated_guards =
"if failed then error(result) end\n".repeat(STACKED_PCALL_ALIAS_GUARDS);
let block = format!(
r#"
---@return integer
local function foo()
return 1
end

local ok, result = pcall(foo)
local failed = ok == false

{repeated_guards}
narrowed = result
"#,
);

let file_id = ws.def(&block);

assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked pcall alias guard repro"
);
assert_eq!(ws.expr_ty("narrowed"), ws.ty("integer"));
}
}
Loading
Loading