1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#[cfg(test)]
mod test {
use crate::{DiagnosticCode, VirtualWorkspace};
#[test]
fn test() {
let mut ws = VirtualWorkspace::new();
assert!(!ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@class Test
local Test = {}
---@param a string
function Test.name(a)
end
Test:name("")
"#
));
assert!(!ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@class Test2
local Test = {}
---@param a string
function Test.name(a)
end
Test.name("", "")
"#
));
assert!(!ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@class A
---@field event fun()
---@type A
local a = {
event = function(aaa)
end,
}
"#
));
}
#[test]
fn test_1() {
let mut ws = VirtualWorkspace::new();
assert!(ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@type fun(...)[]
local a = {}
a[1] = function(ccc, ...)
end
"#
));
}
#[test]
fn test_dots() {
let mut ws = VirtualWorkspace::new();
assert!(ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@class Test
local Test = {}
---@param a string
---@param ... any
function Test.dots(a, ...)
print(a, ...)
end
Test.dots(1, 2, 3)
Test:dots(1, 2, 3)
"#
));
}
#[test]
fn test_issue_360() {
let mut ws = VirtualWorkspace::new();
assert!(!ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@alias buz number
---@param a buz
---@overload fun(): number
function test(a)
end
local c = test({'test'})
"#
));
}
#[test]
fn test_function_param() {
let mut ws = VirtualWorkspace::new();
assert!(!ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
---@class D30
local M = {}
---@param callback fun()
local function with_local(callback)
end
function M:add_local_event()
with_local(function(local_player) end)
end
"#
));
}
#[test]
fn test_generic_infer_function() {
// temp disable this test, future fix this
// let mut ws = VirtualWorkspace::new();
// ws.def(
// r#"
// ---@alias Parameters<T extends function> T extends (fun(...: infer P): any) and P or never
// ---@alias Procedure fun(...: any[]): any
// ---@alias MockParameters<T> T extends Procedure and Parameters<T> or never
// ---@class Mock<T>
// ---@field calls MockParameters<T>[]
// ---@overload fun(...: MockParameters<T>...)
// ---@generic T: Procedure
// ---@param a T
// ---@return Mock<T>
// function fn(a)
// end
// sum = fn(function(a, b)
// return a + b
// end)
// "#,
// );
// assert!(!ws.check_code_for(
// DiagnosticCode::RedundantParameter,
// r#"
// sum(1, 2, 3)
// "#
// ));
}
#[test]
fn test_issue_894() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
_nop = function() end
"#,
);
assert!(ws.check_code_for(
DiagnosticCode::RedundantParameter,
r#"
function a(...) _nop(...) end
"#
));
}
}