Skip to content

Commit 11d63dc

Browse files
committed
fix #317
1 parent 98238d7 commit 11d63dc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,22 @@ mod test {
194194
"#
195195
));
196196
}
197+
198+
#[test]
199+
fn test_issue_317() {
200+
let mut ws = VirtualWorkspace::new();
201+
assert!(ws.check_code_for(
202+
DiagnosticCode::UndefinedField,
203+
r#"
204+
--- @class A
205+
--- @field [string] string
206+
--- @field [integer] integer
207+
local foo = {}
208+
209+
local bar = foo[1]
210+
211+
212+
"#
213+
));
214+
}
197215
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,10 @@ fn infer_member_by_index_custom_type(
511511
.ok_or(InferFailReason::None)?;
512512
let operand = operator.get_operand(db);
513513
let return_type = operator.get_result(db)?;
514-
let typ = infer_index_metamethod(db, cache, &index_key, &operand, &return_type)?;
515-
return Ok(typ);
514+
let typ = infer_index_metamethod(db, cache, &index_key, &operand, &return_type);
515+
if let Ok(typ) = typ {
516+
return Ok(typ);
517+
}
516518
}
517519
}
518520

0 commit comments

Comments
 (0)