LuaLS / LuaLS/lua-language-server
Generic type inference breaks for class-style tables with indexed fields (---@class list<T>: { [integer]: T })
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
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?
Type Checking
Expected Behaviour
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- expected: string
local vBB1 = testBB[1] -- expected: integer
local vAA2 = testAA:at(1) -- expected: string
local vBB2 = testBB:at(1) -- expected: integer
---@type list<number>
local testCC = List {}
-- newList -> expected: list<number>
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> expected: number
local front = newList:front()
Actual Behaviour
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- actual: string|<T>
local vBB1 = testBB[1] -- actual: string|<T>
local vAA2 = testAA:at(1) -- actual: unknown
local vBB2 = testBB:at(1) -- actual: unknown
---@type list<number>
local testCC = List {}
-- newList -> actual: list<<T>>
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> actual: unknown
local front = newList:front()
Reproduction steps
---@meta
---@generic T
---@param t T[]
---@return list<T>
function List(t)
return listlib:new(t);
end
---@class list<T>: { [integer] : T }
listlib = {}
---@generic T
---@param t T[]
---@return list<T>
function listlib:new(t) end
---@generic T
---@param self list<T>
---@param index integer
---@return T
function listlib:at(index) end
---@generic T
---@param self list<T>
---@return T
function listlib:front() end
---@generic T
---@param self list<T>
---@param predicate fun(a: T): boolean
---@return list<T>
function listlib:whereList(predicate) end
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- expected: string, actual: string|<T>
local vBB1 = testBB[1] -- expected: integer, actual: string|<T>
local vAA2 = testAA:at(1) -- expected: string, actual: unknown
local vBB2 = testBB:at(1) -- expected: integer, actual: unknown
---@type list<number>
local testCC = List {}
-- newList -> expected: list<number>, actual: list<<T>>
-- front -> expected: number ,actual: unknown
local newList = testCC:whereList(function(a) return a == 0 end)
local front = newList:front()
Additional Notes
No response
Log File
No response
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
Riprodurre l’esempio minimo Lua nell’estensione Visual Studio Code, iniziando dalle dichiarazioni generiche List/listlib e dall’annotazione della lista in stile classe. Tracciare l’inferenza dei tipi per indexed access, at, whereList e front. Il lavoro è completato quando i tipi inferiti corrispondono ai risultati attesi string, integer e number invece di essere unknown o tipi generici non risolti.
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
- 48/100