Wrong return type for file:read
See original GitHub issueLuanalysis v1.2.3
local function file_contains(filename, text)
local f = assert(io.open(filename, "r"))
local found = f:read("a"):find(text, 1, true)
f:close()
return found
end
What happens?
No such member ‘find’ found on type ‘void’
What were you expecting to happen?
No error message since f:read("a")
returns a string.
This is related to https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/issues/80, where the return type depends on the string value of the first argument as well. Since the type system allows string values as separate types, this one should be solvable with a few overrides though, at least for the most common formats.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Task has a wrong return type
Task has a wrong return type · No Task in your Button Click event. Just async . It's an event handler. Returns nothing....
Read more >FileReader: error event - Web APIs | MDN
The error event is fired when the read failed due to an error (for example, because the file was not found or not...
Read more >fopen - Manual
Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen()...
Read more >Function FileRead
Return Value ; Success: the binary/string read. @extended is set to the number of bytes/characters returned. ; Failure: sets the @error flag to...
Read more >WriteFile function (fileapi.h) - Win32 apps
If the function fails, or is completing asynchronously, the return value is zero (FALSE). To get extended error information, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I still need to write tests, but seems as this is being actively discussed. I’m currently looking at typing
file:read
andio.read
as:5.0-5.1
5.2
5.3-5.4
Basically, at present it’s impossible to properly type this function. We’d need some pretty elaborate type transform logic to make it work 100% reliably i.e. the nth output type is dependent on the nth input type.
However, I believe the above should cover off the most common use cases.
Wow, that already looks impressively accurate, given that the specification of
file:read
would stretch each and every type system beyond its limits. Well, except for human brains, which apparently are even more flexible at accepting exceptional rules. 🙂