Skip to content

Commit d5f05b1

Browse files
committed
Fix #803
1 parent a218090 commit d5f05b1

File tree

1 file changed

+24
-0
lines changed
  • crates/emmylua_code_analysis/src/semantic/type_check

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ fn check_general_type_compact(
5454
return Ok(());
5555
}
5656

57+
if fast_eq_check(source, compact_type) {
58+
return Ok(());
59+
}
60+
5761
if let Some(origin_type) = escape_type(context.db, compact_type) {
5862
return check_general_type_compact(
5963
context,
@@ -160,6 +164,26 @@ fn is_like_any(ty: &LuaType) -> bool {
160164
)
161165
}
162166

167+
fn fast_eq_check(a: &LuaType, b: &LuaType) -> bool {
168+
match (a, b) {
169+
(LuaType::Nil, LuaType::Nil)
170+
| (LuaType::Table, LuaType::Table)
171+
| (LuaType::Userdata, LuaType::Userdata)
172+
| (LuaType::Function, LuaType::Function)
173+
| (LuaType::Thread, LuaType::Thread)
174+
| (LuaType::Boolean, LuaType::Boolean)
175+
| (LuaType::String, LuaType::String)
176+
| (LuaType::Integer, LuaType::Integer)
177+
| (LuaType::Number, LuaType::Number)
178+
| (LuaType::Io, LuaType::Io)
179+
| (LuaType::Global, LuaType::Global)
180+
| (LuaType::Unknown, LuaType::Unknown)
181+
| (LuaType::Any, LuaType::Any) => true,
182+
(LuaType::Ref(type_id_left), LuaType::Ref(type_id_right)) => type_id_left == type_id_right,
183+
_ => false,
184+
}
185+
}
186+
163187
fn escape_type(db: &DbIndex, typ: &LuaType) -> Option<LuaType> {
164188
match typ {
165189
LuaType::Ref(type_id) => {

0 commit comments

Comments
 (0)