Skip to content

Commit bc37072

Browse files
committed
fix index_expr member not find Tuple key
1 parent 2391a32 commit bc37072

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,34 @@ mod test {
508508
"#
509509
));
510510
}
511+
512+
#[test]
513+
fn test_ref_field() {
514+
let mut ws = VirtualWorkspace::new();
515+
assert!(ws.check_code_for(
516+
DiagnosticCode::UndefinedField,
517+
r#"
518+
---@enum ReactiveFlags
519+
local ReactiveFlags = {
520+
IS_REF = { '<IS_REF>' },
521+
}
522+
local IS_REF = ReactiveFlags.IS_REF
523+
524+
---@class ObjectRefImpl
525+
local ObjectRefImpl = {}
526+
527+
function ObjectRefImpl.new()
528+
---@class (constructor) ObjectRefImpl
529+
local self = {
530+
[IS_REF] = true, -- 标记为ref
531+
}
532+
end
533+
534+
---@param a ObjectRefImpl
535+
local function name(a)
536+
local c = a[IS_REF]
537+
end
538+
"#
539+
));
540+
}
511541
}

crates/emmylua_code_analysis/src/semantic/infer/infer_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ fn expr_to_member_key(
10521052
stack.push(t.clone());
10531053
}
10541054
}
1055-
LuaType::TableConst(_) => {
1055+
LuaType::TableConst(_) | LuaType::Tuple(_) => {
10561056
keys.insert(LuaMemberKey::Expr(expr_type.clone()));
10571057
}
10581058
LuaType::Ref(id) => {

0 commit comments

Comments
 (0)