Skip to content

Commit 5f0efc4

Browse files
committed
Generic return can be optional.
1 parent 174a333 commit 5f0efc4

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
```
1414
* `NEW` Test CLI: `--name=<testname>` `-n=<testname>`: run specify unit test
1515
* `FIX` Fixed the error that the configuration file pointed to by the `--configpath` option was not read and loaded.
16+
* `FIX` Generic return can be optional.
1617

1718
## 3.13.5
1819
`2024-12-20`

script/vm/generic.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ function mt:resolve(uri, args)
136136
end
137137
end
138138
end
139+
if protoNode:isOptional() then
140+
result:addOptional()
141+
end
139142
return result
140143
end
141144

test/diagnostics/missing-return.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,21 @@ function F()
156156
157157
end
158158
]]
159+
160+
TEST [[
161+
---@generic T
162+
---@param t T
163+
---@return T
164+
function F(t)
165+
return t
166+
end
167+
]]
168+
169+
TEST [[
170+
---@generic T
171+
---@param t T
172+
---@return T?
173+
function F(t)
174+
175+
end
176+
]]

test/type_inference/common.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,32 @@ end
359359
local _, _, _, <?b?>, _ = x(nil, true, 1, 'yy')
360360
]]
361361

362+
TEST 'nil' [[
363+
local <?k?>, <?v?> = next()
364+
local <?k?>, <?v?> = next({})
365+
]]
366+
367+
TEST 'integer?' [[
368+
local <?k?>, <?v?> = next({1})
369+
]]
370+
371+
TEST 'integer?' [[
372+
local a
373+
local <?k?>, v = next({a})
374+
]]
375+
376+
-- probably explicit unknown generic should be unknown
377+
TEST 'nil' [[
378+
local a
379+
local k, <?v?> = next({a})
380+
]]
381+
362382
TEST 'unknown' [[
363-
local <?x?> = next()
383+
---@generic T
384+
---@param t T?
385+
---@return T
386+
local function F(t) end
387+
local <?x?> = F()
364388
]]
365389

366390
TEST 'unknown' [[

0 commit comments

Comments
 (0)