Skip to content

Commit 2c26700

Browse files
committed
#1091 fix runtime errors
1 parent f4b84ee commit 2c26700

File tree

5 files changed

+44
-30
lines changed

5 files changed

+44
-30
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 3.2.2
4+
* `FIX` runtime errors reported by telemetry, see [#1091](https://github.com/sumneko/lua-language-server/issues/1091)
5+
36
## 3.2.1
47
`2022-4-25`
58
* `FIX` broken in VSCode

script/vm/compiler.lua

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ local function selectNode(source, list, index)
647647
if exp.type == 'call' then
648648
result = getReturn(exp.node, index, exp.args)
649649
if not result then
650-
vm.setNode(source, globalMgr.getGlobal('type', 'unknown'))
650+
vm.setNode(source, globalMgr.declareGlobal('type', 'unknown'))
651651
return vm.getNode(source)
652652
end
653653
else
@@ -673,7 +673,7 @@ local function selectNode(source, list, index)
673673
end
674674
end
675675
if not hasKnownType then
676-
rtnNode:merge(globalMgr.getGlobal('type', 'unknown'))
676+
rtnNode:merge(globalMgr.declareGlobal('type', 'unknown'))
677677
end
678678
vm.setNode(source, rtnNode)
679679
return rtnNode
@@ -877,7 +877,7 @@ local function compileLocal(source)
877877
end
878878
end
879879
if not hasDocArg then
880-
vm.setNode(source, globalMgr.getGlobal('type', 'any'))
880+
vm.setNode(source, globalMgr.declareGlobal('type', 'any'))
881881
end
882882
end
883883
-- for x in ... do
@@ -1252,7 +1252,7 @@ local compilerSwitch = util.switch()
12521252
: case 'loop'
12531253
: call(function (source)
12541254
if source.loc then
1255-
vm.setNode(source.loc, globalMgr.getGlobal('type', 'integer'))
1255+
vm.setNode(source.loc, globalMgr.declareGlobal('type', 'integer'))
12561256
end
12571257
end)
12581258
: case 'doc.type'
@@ -1278,6 +1278,9 @@ local compilerSwitch = util.switch()
12781278
: call(function (source)
12791279
local uri = guide.getUri(source)
12801280
vm.setNode(source, source)
1281+
if not source.node[1] then
1282+
return
1283+
end
12811284
local global = globalMgr.getGlobal('type', source.node[1])
12821285
if not global then
12831286
return
@@ -1377,7 +1380,7 @@ local compilerSwitch = util.switch()
13771380
if source.extends then
13781381
vm.setNode(source, vm.compileNode(source.extends))
13791382
else
1380-
vm.setNode(source, globalMgr.getGlobal('type', 'any'))
1383+
vm.setNode(source, globalMgr.declareGlobal('type', 'any'))
13811384
end
13821385
if source.optional then
13831386
vm.getNode(source):addOptional()
@@ -1392,10 +1395,13 @@ local compilerSwitch = util.switch()
13921395
if bindAs(source) then
13931396
return
13941397
end
1398+
if not source[1] then
1399+
return
1400+
end
13951401
if source.op.type == 'not' then
13961402
local result = vm.test(source[1])
13971403
if result == nil then
1398-
vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
1404+
vm.setNode(source, globalMgr.declareGlobal('type', 'boolean'))
13991405
return
14001406
else
14011407
vm.setNode(source, {
@@ -1409,13 +1415,13 @@ local compilerSwitch = util.switch()
14091415
end
14101416
end
14111417
if source.op.type == '#' then
1412-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1418+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
14131419
return
14141420
end
14151421
if source.op.type == '-' then
14161422
local v = vm.getNumber(source[1])
14171423
if v == nil then
1418-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1424+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
14191425
return
14201426
else
14211427
vm.setNode(source, {
@@ -1431,7 +1437,7 @@ local compilerSwitch = util.switch()
14311437
if source.op.type == '~' then
14321438
local v = vm.getInteger(source[1])
14331439
if v == nil then
1434-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1440+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
14351441
return
14361442
else
14371443
vm.setNode(source, {
@@ -1450,6 +1456,9 @@ local compilerSwitch = util.switch()
14501456
if bindAs(source) then
14511457
return
14521458
end
1459+
if not source[1] or not source[2] then
1460+
return
1461+
end
14531462
if source.op.type == 'and' then
14541463
local node1 = vm.compileNode(source[1])
14551464
local node2 = vm.compileNode(source[2])
@@ -1479,7 +1488,7 @@ local compilerSwitch = util.switch()
14791488
if source.op.type == '==' then
14801489
local result = vm.equal(source[1], source[2])
14811490
if result == nil then
1482-
vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
1491+
vm.setNode(source, globalMgr.declareGlobal('type', 'boolean'))
14831492
return
14841493
else
14851494
vm.setNode(source, {
@@ -1495,7 +1504,7 @@ local compilerSwitch = util.switch()
14951504
if source.op.type == '~=' then
14961505
local result = vm.equal(source[1], source[2])
14971506
if result == nil then
1498-
vm.setNode(source, globalMgr.getGlobal('type', 'boolean'))
1507+
vm.setNode(source, globalMgr.declareGlobal('type', 'boolean'))
14991508
return
15001509
else
15011510
vm.setNode(source, {
@@ -1521,7 +1530,7 @@ local compilerSwitch = util.switch()
15211530
})
15221531
return
15231532
else
1524-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1533+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
15251534
return
15261535
end
15271536
end
@@ -1538,7 +1547,7 @@ local compilerSwitch = util.switch()
15381547
})
15391548
return
15401549
else
1541-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1550+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
15421551
return
15431552
end
15441553
end
@@ -1555,7 +1564,7 @@ local compilerSwitch = util.switch()
15551564
})
15561565
return
15571566
else
1558-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1567+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
15591568
return
15601569
end
15611570
end
@@ -1572,7 +1581,7 @@ local compilerSwitch = util.switch()
15721581
})
15731582
return
15741583
else
1575-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1584+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
15761585
return
15771586
end
15781587
end
@@ -1589,7 +1598,7 @@ local compilerSwitch = util.switch()
15891598
})
15901599
return
15911600
else
1592-
vm.setNode(source, globalMgr.getGlobal('type', 'integer'))
1601+
vm.setNode(source, globalMgr.declareGlobal('type', 'integer'))
15931602
return
15941603
end
15951604
end
@@ -1607,7 +1616,7 @@ local compilerSwitch = util.switch()
16071616
})
16081617
return
16091618
else
1610-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1619+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16111620
return
16121621
end
16131622
end
@@ -1625,7 +1634,7 @@ local compilerSwitch = util.switch()
16251634
})
16261635
return
16271636
else
1628-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1637+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16291638
return
16301639
end
16311640
end
@@ -1643,7 +1652,7 @@ local compilerSwitch = util.switch()
16431652
})
16441653
return
16451654
else
1646-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1655+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16471656
return
16481657
end
16491658
end
@@ -1660,7 +1669,7 @@ local compilerSwitch = util.switch()
16601669
})
16611670
return
16621671
else
1663-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1672+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16641673
return
16651674
end
16661675
end
@@ -1678,7 +1687,7 @@ local compilerSwitch = util.switch()
16781687
})
16791688
return
16801689
else
1681-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1690+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16821691
return
16831692
end
16841693
end
@@ -1695,7 +1704,7 @@ local compilerSwitch = util.switch()
16951704
})
16961705
return
16971706
else
1698-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1707+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
16991708
return
17001709
end
17011710
end
@@ -1713,7 +1722,7 @@ local compilerSwitch = util.switch()
17131722
})
17141723
return
17151724
else
1716-
vm.setNode(source, globalMgr.getGlobal('type', 'number'))
1725+
vm.setNode(source, globalMgr.declareGlobal('type', 'number'))
17171726
return
17181727
end
17191728
end
@@ -1750,7 +1759,7 @@ local compilerSwitch = util.switch()
17501759
})
17511760
return
17521761
else
1753-
vm.setNode(source, globalMgr.getGlobal('type', 'string'))
1762+
vm.setNode(source, globalMgr.declareGlobal('type', 'string'))
17541763
return
17551764
end
17561765
end

script/vm/global-manager.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ local compilerGlobalSwitch = util.switch()
209209

210210
---@param cate vm.global.cate
211211
---@param name string
212-
---@param uri uri
212+
---@param uri? uri
213213
---@return vm.global
214214
function m.declareGlobal(cate, name, uri)
215215
local key = cate .. '|' .. name
216-
m.globalSubs[uri][key] = true
216+
if uri then
217+
m.globalSubs[uri][key] = true
218+
end
217219
if not m.globals[key] then
218220
m.globals[key] = globalBuilder(name, cate)
219221
end

script/vm/sign.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function mt:resolve(uri, args, removeGeneric)
5858
end
5959
if n.type == 'global' and n.cate == 'type' then
6060
-- ---@field [integer]: number -> T[]
61-
vm.getClassFields(uri, n, globalMgr.getGlobal('type', 'integer'), false, function (field)
61+
vm.getClassFields(uri, n, globalMgr.declareGlobal('type', 'integer'), false, function (field)
6262
resolve(object.node, vm.compileNode(field.extends))
6363
end)
6464
end

script/vm/type.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function vm.getTableKey(uri, tnode, vnode)
134134
end
135135
end
136136
if tn.type == 'doc.type.array' then
137-
result:merge(globalMgr.getGlobal('type', 'integer'))
137+
result:merge(globalMgr.declareGlobal('type', 'integer'))
138138
end
139139
if tn.type == 'table' then
140140
for _, field in ipairs(tn) do
@@ -144,10 +144,10 @@ function vm.getTableKey(uri, tnode, vnode)
144144
end
145145
end
146146
if field.type == 'tablefield' then
147-
result:merge(globalMgr.getGlobal('type', 'string'))
147+
result:merge(globalMgr.declareGlobal('type', 'string'))
148148
end
149149
if field.type == 'tableexp' then
150-
result:merge(globalMgr.getGlobal('type', 'integer'))
150+
result:merge(globalMgr.declareGlobal('type', 'integer'))
151151
end
152152
end
153153
end

0 commit comments

Comments
 (0)