Skip to content

Commit 13c1101

Browse files
committed
Add configuration item doc integer match int
set `strict.docIntegerMatchInt = true` ```lua ---@alias IdAlias ---| 311000001 ---| 311000002 ---@param id IdAlias local function f(id) end ---@type integer local a f(a) -- allow ```
1 parent 6c98c39 commit 13c1101

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"strict": {
160160
"default": {
161161
"arrayIndex": true,
162+
"docIntegerMatchInt": true,
162163
"metaOverrideFileDefine": true,
163164
"requirePath": false,
164165
"typeCall": false
@@ -945,6 +946,11 @@
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,

crates/emmylua_code_analysis/src/config/configs/strict.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2932
impl 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
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

crates/emmylua_code_analysis/src/semantic/type_check/simple_type.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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(());

0 commit comments

Comments
 (0)