feat: resolve class generic parameters in @operator declarations#3437
Open
RomanSpector wants to merge 1 commit into
Open
feat: resolve class generic parameters in @operator declarations#3437RomanSpector wants to merge 1 commit into
RomanSpector wants to merge 1 commit into
Conversation
`vm.runOperator` only understood plain type globals in the callee node, so every operator was silently skipped for parameterized types like `Box<string>`, and `T` inside `@operator call(): T?` was treated as an undefined type name. - luadoc: add doc.operator to the bindGeneric rewrite list so sign names inside operator annotations become doc.generic.name - this both enables generic detection and gives them generic highlighting - vm: handle doc.type.sign in runOperator and substitute class type parameters in operator.exp/operator.extends via getClassGenericMap and cloneObject; match sign operands by their base class - expose containsGenericName as vm.containsGenericName Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Summary
@operatordeclarations on generic classes now resolve the class type parameters through the instantiated type, and generic parameter names used inside@operatorannotations are recognized (and highlighted) as generics instead of undefined type names.Previously
vm.runOperatoronly understood plain type globals in the callee's node, so every operator (call,add,concat, ...) was silently skipped for parameterized types likeBox<string>, andTinside@operatorstayed an undefineddoc.type.name.Implementation
script/parser/luadoc.lua(1 line):bindGenericalready collects generic names from@genericand from class/alias signs and rewritesdoc.type.name→doc.generic.nameinsidedoc.param,doc.return,doc.field,doc.overload, etc. — butdoc.operatorwas missing from the list. Adding it fixes both the semantic highlighting (the existingdoc.generic.nametoken path applies) and the generic detection for inference.script/vm/operator.lua:vm.runOperatorhandlesdoc.type.signobjects in the callee node: the class global is looked up by the sign's base name and its operators are checked with the sign's type arguments.checkOperatorssubstitutes class type parameters inoperator.exp/operator.extendsvia the existingvm.getClassGenericMap+vm.cloneObjectmachinery (same pattern as generic field resolution). When matching the operand of a binary operator, adoc.type.signvalue is matched by its base class, sincevm.isSubTypehas no notion of parameterized types (type arguments are not compared — same as everywhere else in the codebase).script/vm/compiler.lua(3 lines): expose the existing localcontainsGenericNameasvm.containsGenericNamefor reuse.Behavior notes
---@type Boxon---@class Box<T>) now renders the operator result as<T>?instead ofT?— the standard display for an unresolved generic, instead of pretending an undefined classTexists.typeGenericbranch incore/semantic-tokens.luaremains unused by this PR (nothing sets that flag today); the highlight works through the regulardoc.generic.nametoken path.Tests
New
test/type_inference/generic_operator.lua:call/addon instantiated generics, multi-parameter classes (Pair<K, V>), nested signs (Box<Box<string>>), generic operand types (add(Box<T>): T), a real-world shape with inheritance + generic factory, and parity cases (non-generic baseline, signs on a non-generic class, unparameterized reference).@field/@operator/inheritance arguments becomedoc.generic.name(these useguide.eachSourcerather thaneachSourceType, because the type cache of bound docs predates thebindGenericrewrite).Full test suite passes on win32-x64.
🤖 Generated with Claude Code