LuaLS / LuaLS/lua-language-server
FR: Allow 'self' return type to allow return type changing with inheritance
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
When annotating that one class has inherited from another, there is currently no way to annotate a function that returns it's current type that the current type should change when the class is inherited. Something along these lines, or something that accomplishes the same goal would be fantastic.
```lua
---@class Foo
Foo = {}
---@return self --<-- 'self' refers to Foo so Foo.new() returns Foo
function Foo.new() end
---@class Bar : Foo
Bar = {}
local b = Bar.new() --<-- Bar.new() is inherited so the 'self' return type is now Bar
-- b should now be type Bar
```
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Foo/Bar Lua example in the issue and trace how @return annotations and inherited methods are interpreted. Done means a constructor inherited by Bar infers its result as Bar rather than Foo, with coverage for the demonstrated behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100