Skip to content

Commit 2f9ba42

Browse files
committed
Allow global to be used as an identifier in Lua 5.5 when it is not part of a global declaration
1 parent 8932369 commit 2f9ba42

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
"Lua.misc.parameters": [
44
//"--preview",
55
"--develop=true",
6-
"--dbgport=11413",
6+
"--dbgport=11431",
7+
//"--dbgwait",
78
"--loglevel=trace",
9+
"--trace-rpc",
10+
//"--save-coder",
811
//"--shownode",
912
//"--lazy",
1013
],

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5+
* `FIX` Allow `global` to be used as an identifier in Lua 5.5 when it is not part of a `global` declaration
56

67
## 3.18.0
78
`2026-04-03`

script/parser/compile.lua

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,14 +1695,26 @@ local function isKeyWord(word, nextToken)
16951695
return true
16961696
end
16971697
if word == 'global' then
1698-
if State.version == 'Lua 5.5' then
1699-
return true
1700-
end
17011698
return false
17021699
end
17031700
return false
17041701
end
17051702

1703+
local function isGlobalActionStart(nextToken)
1704+
if State.version ~= 'Lua 5.5' then
1705+
return false
1706+
end
1707+
if not nextToken
1708+
or nextToken == '*'
1709+
or nextToken == '<' then
1710+
return true
1711+
end
1712+
if CharMapWord[ssub(nextToken, 1, 1)] then
1713+
return true
1714+
end
1715+
return false
1716+
end
1717+
17061718
local function parseName(asAction)
17071719
local word = peekWord()
17081720
if not word then
@@ -4441,13 +4453,8 @@ function parseAction()
44414453

44424454
if token == 'global' then
44434455
local nextToken = Tokens[Index + 3]
4444-
if isKeyWord('global', nextToken) then
4445-
if not nextToken
4446-
or nextToken == '*'
4447-
or nextToken == '<'
4448-
or CharMapWord[ssub(nextToken, 1, 1)] then
4449-
return parseGlobal()
4450-
end
4456+
if isGlobalActionStart(nextToken) then
4457+
return parseGlobal()
44514458
end
44524459
end
44534460

test/parser_test/syntax_check.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,17 @@ global <const> x = 1
867867
]]
868868
(nil)
869869

870+
TEST [[
871+
global = 1
872+
]]
873+
(nil)
874+
875+
TEST [[
876+
local global = 1
877+
return global
878+
]]
879+
(nil)
880+
870881
TEST [[
871882
local <close>x = setmetatable({}, { __close = function () end })
872883
]]

0 commit comments

Comments
 (0)