LuaLS / LuaLS/lua-language-server

Generics Return Issue

Aperta
#2,188 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement feat/generic
Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Annotations

Expected Behaviour

In this function:

--- Merge two tables together, keys that are the same will use the value from the second table
---@generic K, V, L, W
---@param table1 table<K, V>
---@param table2 table<L, W>
---@return table<K | L, V | W>
function table.merge(table1, table2)
	for k, v in pairs(table2) do
		table1[k] = v
	end

	return table1
end

I would expect the return type to be table<K | L, V | W> however it is actually always table<K, V>
There is also a secondary issue here where k, v are seen as unknown when they should be seen as V, W (I assume this is another generics issue)

Actual Behaviour
Screenshot_1 Screenshot_2
Reproduction steps
  1. Copy example code
  2. Observe result
Additional Notes

No response

Log File

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci l’esempio annotato di table.merge nell’estensione Visual Studio Code su Windows. Inizia tracciando l’annotazione generica e l’inferenza dei tipi di tabella per @generic, @param, @return e pairs; il lavoro è completato quando il valore restituito è table<K | L, V | W> e k e v vengono risolti nei tipi della seconda tabella.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua, vscode
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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.