File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
crates/emmylua_code_analysis/src Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -600,7 +600,18 @@ impl LuaObjectType {
600600
601601 pub fn cast_down_array_base ( & self ) -> Option < LuaType > {
602602 if self . index_access . len ( ) != 0 {
603- return None ;
603+ let mut ty = None ;
604+ for ( key, value_type) in self . index_access . iter ( ) {
605+ if matches ! ( key, LuaType :: Integer ) {
606+ if ty. is_none ( ) {
607+ ty = Some ( LuaType :: Unknown ) ;
608+ }
609+ if let Some ( t) = ty {
610+ ty = Some ( TypeOps :: Union . apply ( & t, value_type) ) ;
611+ }
612+ }
613+ }
614+ return ty;
604615 }
605616
606617 let mut ty = LuaType :: Unknown ;
Original file line number Diff line number Diff line change @@ -756,4 +756,24 @@ mod test {
756756 "#
757757 ) ) ;
758758 }
759+
760+ #[ test]
761+ fn test_generic_array ( ) {
762+ let mut ws = VirtualWorkspace :: new ( ) ;
763+ assert ! ( ws. check_code_for(
764+ DiagnosticCode :: ParamTypeNotMatch ,
765+ r#"
766+ ---@class LocalTimer
767+
768+ ---@generic V
769+ ---@param list V[]
770+ ---@return integer
771+ local function sort(list) end
772+
773+ ---@type { need_sort: true?, [integer]: LocalTimer }
774+ local queue = {}
775+ sort(queue)
776+ "#
777+ ) ) ;
778+ }
759779}
You can’t perform that action at this time.
0 commit comments