LuaLS / LuaLS/lua-language-server
Problem with generics
Nessuno ha ancora preso questa issue.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!
I'm working on an OOP library and here's a truncated example of the constructor it uses:
---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end
The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.
When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:
---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}
---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}
local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2
But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Non viene indicato alcun file sorgente né alcun test. Riproduci l’esempio di costruttore generico nel Lua language server e controlla come viene inferito il completamento all’interno degli argomenti tabella vuoti quando il primo argomento è Example1 o Example2. Il lavoro è completato quando i campi rilevanti della classe vengono suggeriti in quei letterali tabella, preservando al contempo il tipo di risultato inferito esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100