IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
void can't seem to be an alternative return type in function retval annotations
Environment
name | version |
---|---|
IDEA version | 2020.3.1 (IC-203.6682.168) |
Luanalysis version | 1.2.2 and also repro'd in latest master (now 5018fdb14e170ccfcdaa1359a4db2e662a8dbd27) |
OS | Linux Ubuntu 20.10 |
What are the steps to reproduce this issue?
---@alias Handler fun(): (void | nil)
---@type Handler
local myFunc3 = function() end
---@type Handler
local myFunc4 = function() return nil end
What happens?
Error on the function definition:
Type mismatch. Required: 'fun(): nil' Found: 'fun(): void'
What were you expecting to happen?
For void
to be able to be accepted as an alternative return type.
This is a bit of a weird one. The syntax is functioning as is (currently) intended. However, it's certainly not what you want.
Each time you see someType | someOtherType
you're creating a set. void
is itself the absence of a type i.e. the empty set. So when you create a union of an empty set and some other set, the result is always whatever the other type/set was.
I'll have to have a think about this one. The reason I'm reluctant to treat void
like a regular type is that Lua has fairly complicated semantics surrounding the absence of a value i.e. most of the time it's coerced to nil
, but certainly not all the time.
Oh, I see. The error makes sense now. And indeed, void isn't the same as nil all the time :)
Looking forward to what you'll come up with!