Skip to content

docs(wiki): document generic classes in @generic section#144

Open
xiangnanscu wants to merge 1 commit into
LuaLS:mainfrom
xiangnanscu:docs-generic-classes
Open

docs(wiki): document generic classes in @generic section#144
xiangnanscu wants to merge 1 commit into
LuaLS:mainfrom
xiangnanscu:docs-generic-classes

Conversation

@xiangnanscu

Copy link
Copy Markdown

Description

The @generic section still says generics are limited to functions and index-signature classes (Array<T>: { [integer]: T }), and does not mention the generic-class features that landed in v3.17.0:

  • generic class inheritance with type arguments (#1929)
  • method return type resolution on generic classes (#1863)
  • generic type parameters in @overload (#723)
  • inline fun<T> generic function types in @field/@type (#1170)

This PR:

  • adds one sentence to the section intro listing the v3.17.0 additions
  • adds a Generic Class with Fields and Methods example, covering ---@class Box<T> with ---@field value T / ---@field get fun(self: Box<T>): T, and inheritance from an instantiated generic class (---@class IntegerBox: Box<integer>), with a note describing when the type parameter is substituted (members declared as ---@field entries substitute both on direct instantiation and through inheritance; separately declared methods only substitute when the receiver's type is the instantiated generic class itself)
  • adds an Inline Generic Function Type example (---@field identity fun<T>(value: T): T)

Verification

Every example was verified against lua-language-server 3.18.2 by running lua-language-server --check over probe files that assign each documented expression to an intentionally wrong type and asserting the expected assign-type-mismatch diagnostics appear (and that no diagnostics appear where substitution is documented to work).

🤖 Generated with Claude Code

The @Generic section predates v3.17.0 and did not mention that classes
can declare type parameters beyond the index-signature examples. Add:

- a sentence in the intro listing the v3.17.0 additions (generic class
  inheritance with type arguments, generic parameters in @overload,
  inline fun<T> function types in @field/@type)
- an example of a generic class with fields and methods, including
  inheritance from an instantiated generic class, with a note on when
  type parameters are substituted
- an example of the inline fun<T> generic function type

All examples verified against lua-language-server 3.18.2 using --check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant