luau icon indicating copy to clipboard operation
luau copied to clipboard

`collectgarbage` is "unknown global" in analysis and incorrectly documented

Open fewkz opened this issue 2 years ago • 1 comments

When using luau-analyze, it warns that collectgarbage is an unknown global despite this not being the case. collectgarbage should be added as a global in analysis, with it's parameter typed as taking "collect" and "count"

I use the collectgarbage("collect") method intensively in test cases for a library I'm working on (fewkz/cells/test.luau) to ensure there's no memory leaks, it's an invaluable method, but luau-analyze keeps complaining about it not existing.

In the Luau documentation, the collectgarbage function is incorrectly documented as not taking "collect" as an argument, despite this working perfectly fine, and indeed collecting garbage. The code collectgarbage("foo") even results in the error "collectgarbage must be called with 'count' or 'collect'" The documentation should be changed to reflect that "collect" is a valid argument to collectgarbage on https://luau-lang.org/sandbox image

fewkz avatar Nov 13 '22 16:11 fewkz

This is messy and requires some sort of resolution :( It has to do with differences between Luau and Roblox library environment, and documentation / type checking being conservative. We'll need to figure out how to resolve this.

zeux avatar Feb 15 '23 22:02 zeux