ldoc
ldoc copied to clipboard
Bug in the name for `new` method in class module (colon instead of dot generated)
Code
---
-- A Class Module
-- @classmod ClassModule
local ClassModule = {}
--- Create a new ClassModule
-- @return a new ClassModule object
function ClassModule.new()
return nil
end
--- Do something with ClassModule object.
function ClassModule:doSomething()
end
Running ldoc
ldoc ClassModule.lua
Result
See screenshot below. Note how ClassModule.new is documented as ClassModule:new

Expected Result
The ClassModule.new function should be documented with the single dot, but instead it is documented with a colon.
Other info
I see this behavior, even if I document the module with the @module directive, and include a @type directive somewhere below the @module directive. The only way it works is if I use a different module name and a different type name. For example:
---
-- A Class Module
-- @module Module
--- ClassModule
-- @type ClassModule
local ClassModule = {}
--- Create a new ClassModule
-- @return a new ClassModule object
function ClassModule.new()
return nil
end
--- Do something with ClassModule object.
function ClassModule:doSomething()
end
See screenshot below:

Is this a bug? If not, please suggest a workaround, if you can think of any.
-- @function ClassModule.new
I just had a look at this and it seems it is still not fixed. @RyanSquared your tip doesn't seem to fix it either, was that something you expected to generate the expected output or a suggestion for how it could be fixed?
I believe this was something that worked at the time. Something like:
--- Create a new ClassModule
-- @function ClassModule.new()
-- @return ClassModule
function ClassModule.new()
return nil
end
~~it's been a few years, pls forgive if i don't remember exactly~~
Hmm, interesting, that does actually work and gives the expected output with the caveat that you have to use --not_luadoc for that exact MWE (one could possibly rearrange it to avoid that).