File tree Expand file tree Collapse file tree 3 files changed +249
-217
lines changed
crates/emmylua_code_analysis/src Expand file tree Collapse file tree 3 files changed +249
-217
lines changed Original file line number Diff line number Diff line change @@ -192,7 +192,8 @@ impl LuaTypeDecl {
192192 let fake_type = match member_key {
193193 LuaMemberKey :: Name ( name) => LuaType :: DocStringConst ( name. clone ( ) . into ( ) ) ,
194194 LuaMemberKey :: Integer ( i) => LuaType :: IntegerConst ( i. clone ( ) ) ,
195- LuaMemberKey :: None | LuaMemberKey :: ExprType ( _) => continue ,
195+ LuaMemberKey :: ExprType ( typ) => typ. clone ( ) ,
196+ LuaMemberKey :: None => continue ,
196197 } ;
197198
198199 union_types. push ( fake_type) ;
Original file line number Diff line number Diff line change @@ -1044,4 +1044,49 @@ mod test {
10441044 "#
10451045 ) ) ;
10461046 }
1047+
1048+ #[ test]
1049+ fn test_enum_value_matching ( ) {
1050+ let mut ws = VirtualWorkspace :: new ( ) ;
1051+ assert ! ( ws. check_code_for(
1052+ DiagnosticCode :: ParamTypeNotMatch ,
1053+ r#"
1054+ ---@enum SlotType
1055+ local SlotType = {
1056+ bag = 0,
1057+ item = 1,
1058+ }
1059+
1060+ ---@enum ConstSlotType
1061+ local ConstSlotType = {
1062+ ['NOT_IN_BAG'] = -1,
1063+ ['PKG'] = 0,
1064+ ['BAR'] = 1,
1065+ }
1066+
1067+ ---@param type ConstSlotType
1068+ local function get_item_by_slot(type)
1069+ end
1070+
1071+ ---@param field SlotType
1072+ local function bind_unit_slot(field)
1073+ get_item_by_slot(field)
1074+ end"#
1075+ ) ) ;
1076+ }
1077+
1078+ #[ test]
1079+ fn test_enum_value_matching_2 ( ) {
1080+ let mut ws = VirtualWorkspace :: new_with_init_std_lib ( ) ;
1081+ assert ! ( ws. check_code_for(
1082+ DiagnosticCode :: ParamTypeNotMatch ,
1083+ r#"
1084+ ---@enum DamageType
1085+ local DamageType = {
1086+ ['物理'] = "物理",
1087+ }
1088+ for _, damageType in pairs(DamageType) do end
1089+ "#
1090+ ) ) ;
1091+ }
10471092}
You can’t perform that action at this time.
0 commit comments