Skip to content

Commit a6fbcf0

Browse files
committed
Fix #246
1 parent 951a14c commit a6fbcf0

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

crates/emmylua_code_analysis/src/diagnostic/test/assign_type_mismatch_test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,21 @@ return t
573573
"#
574574
));
575575
}
576+
577+
#[test]
578+
fn test_issue_246() {
579+
let mut ws = VirtualWorkspace::new();
580+
assert!(ws.check_code_for(
581+
DiagnosticCode::AssignTypeMismatch,
582+
r#"
583+
--- @alias Type1 'add' | 'change' | 'delete'
584+
--- @alias Type2 'add' | 'change' | 'delete' | 'untracked'
585+
586+
local ty1 --- @type Type1?
587+
588+
--- @type Type2
589+
local _ = ty1 or 'untracked'
590+
"#
591+
));
592+
}
576593
}

crates/emmylua_code_analysis/src/semantic/type_check/complex_type/mod.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn check_complex_type_compact(
5757
LuaType::Union(compact_union) => {
5858
return check_union_type_compact_union(
5959
db,
60-
union_type,
60+
source,
6161
compact_union,
6262
check_guard.next_level()?,
6363
);
@@ -111,29 +111,15 @@ pub fn check_complex_type_compact(
111111
// too complex
112112
fn check_union_type_compact_union(
113113
db: &DbIndex,
114-
source_union: &LuaUnionType,
114+
source: &LuaType,
115115
compact_union: &LuaUnionType,
116116
check_guard: TypeCheckGuard,
117117
) -> TypeCheckResult {
118-
let source_types = source_union.get_types();
119118
let compact_types = compact_union.get_types();
120119
for compact_sub_type in compact_types {
121-
let mut is_match = false;
122-
for source_sub_type in source_types {
123-
if check_general_type_compact(
124-
db,
125-
source_sub_type,
126-
compact_sub_type,
127-
check_guard.next_level()?,
128-
)
129-
.is_ok()
130-
{
131-
is_match = true;
132-
break;
133-
}
134-
}
135-
136-
if !is_match {
120+
if check_general_type_compact(db, source, compact_sub_type, check_guard.next_level()?)
121+
.is_err()
122+
{
137123
return Err(TypeCheckFailReason::TypeNotMatch);
138124
}
139125
}

0 commit comments

Comments
 (0)