docs(wiki): document generic classes in @generic section#144
Open
xiangnanscu wants to merge 1 commit into
Open
docs(wiki): document generic classes in @generic section#144xiangnanscu wants to merge 1 commit into
xiangnanscu wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
@genericsection 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:@overload(#723)fun<T>generic function types in@field/@type(#1170)This PR:
---@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---@fieldentries substitute both on direct instantiation and through inheritance; separately declared methods only substitute when the receiver's type is the instantiated generic class itself)---@field identity fun<T>(value: T): T)Verification
Every example was verified against lua-language-server 3.18.2 by running
lua-language-server --checkover probe files that assign each documented expression to an intentionally wrong type and asserting the expectedassign-type-mismatchdiagnostics appear (and that no diagnostics appear where substitution is documented to work).🤖 Generated with Claude Code