File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed
crates/emmylua_code_analysis Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 159159 "strict" : {
160160 "default" : {
161161 "arrayIndex" : true ,
162+ "docIntegerMatchInt" : true ,
162163 "metaOverrideFileDefine" : true ,
163164 "requirePath" : false ,
164165 "typeCall" : false
945946 "default" : true ,
946947 "type" : " boolean"
947948 },
949+ "docIntegerMatchInt" : {
950+ "description" : " The `int` type can match the `doc_integer` type. applied to `alias`." ,
951+ "default" : false ,
952+ "type" : " boolean"
953+ },
948954 "metaOverrideFileDefine" : {
949955 "description" : " meta define overrides file define" ,
950956 "default" : true ,
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ pub struct EmmyrcStrict {
2424 /// meta define overrides file define
2525 #[ serde( default = "default_true" ) ]
2626 pub meta_override_file_define : bool ,
27+ /// The `int` type can match the `doc_integer` type.
28+ #[ serde( default = "default_false" ) ]
29+ pub doc_integer_match_int : bool ,
2730}
2831
2932impl Default for EmmyrcStrict {
@@ -33,6 +36,7 @@ impl Default for EmmyrcStrict {
3336 type_call : false ,
3437 array_index : true ,
3538 meta_override_file_define : true ,
39+ doc_integer_match_int : true ,
3640 }
3741 }
3842}
Original file line number Diff line number Diff line change @@ -1019,4 +1019,29 @@ mod test {
10191019 "#
10201020 ) ) ;
10211021 }
1022+
1023+ #[ test]
1024+ fn test_int_to_alias ( ) {
1025+ let mut ws = VirtualWorkspace :: new ( ) ;
1026+ let mut emmyrc = ws. analysis . get_emmyrc ( ) . deref ( ) . clone ( ) ;
1027+ emmyrc. strict . doc_integer_match_int = true ;
1028+ ws. analysis . update_config ( Arc :: new ( emmyrc) ) ;
1029+
1030+ assert ! ( ws. check_code_for(
1031+ DiagnosticCode :: ParamTypeNotMatch ,
1032+ r#"
1033+ ---@alias IdAlias
1034+ ---| 311000001
1035+ ---| 311000002
1036+
1037+ ---@param id IdAlias
1038+ local function f(id)
1039+ end
1040+
1041+ ---@type integer
1042+ local a
1043+ f(a)
1044+ "#
1045+ ) ) ;
1046+ }
10221047}
Original file line number Diff line number Diff line change @@ -130,7 +130,12 @@ pub fn check_simple_type_compact(
130130
131131 return Err ( TypeCheckFailReason :: TypeNotMatch ) ;
132132 }
133- LuaType :: Integer => return Err ( TypeCheckFailReason :: TypeNotMatch ) ,
133+ LuaType :: Integer => {
134+ if db. get_emmyrc ( ) . strict . doc_integer_match_int {
135+ return Ok ( ( ) ) ;
136+ }
137+ return Err ( TypeCheckFailReason :: TypeNotMatch ) ;
138+ }
134139 LuaType :: DocIntegerConst ( j) => {
135140 if i == j {
136141 return Ok ( ( ) ) ;
You can’t perform that action at this time.
0 commit comments