@@ -2907,41 +2907,23 @@ local function bindValue(n, v, index, lastValue, isLocal, isSet)
29072907 if n .type == ' setglobal' then
29082908 local gi = State .globalInfo
29092909 local nameKey = n [1 ]
2910- if n . isGlobalDecl then
2911- -- duplicate initialization check (only for global declarations with value)
2910+ -- assignment / definition in strict global scope
2911+ if gi . active then
29122912 local info = gi .names [nameKey ]
2913- if v then
2914- if info and info .initialized then
2915- pushError {
2916- type = ' GLOBAL_DUPLICATE_INIT' ,
2917- start = n .start ,
2918- finish = n .finish ,
2919- }
2920- else
2921- if info then
2922- info .initialized = true
2923- end
2924- end
2913+ if not gi .hasAll and not info then
2914+ pushError {
2915+ type = ' UNDEFINED_IN_GLOBAL_SCOPE' ,
2916+ start = n .start ,
2917+ finish = n .finish ,
2918+ }
29252919 end
2926- else
2927- -- assignment / definition in strict global scope
2928- if gi .active then
2929- local info = gi .names [nameKey ]
2930- if not gi .hasAll and not info then
2931- pushError {
2932- type = ' UNDEFINED_IN_GLOBAL_SCOPE' ,
2933- start = n .start ,
2934- finish = n .finish ,
2935- }
2936- end
2937- local isConst = (info and info .const ) or gi .allConst
2938- if isConst then
2939- pushError {
2940- type = ' ASSIGN_CONST_GLOBAL' ,
2941- start = n .start ,
2942- finish = n .finish ,
2943- }
2944- end
2920+ local isConst = (info and info .const ) or gi .allConst
2921+ if isConst then
2922+ pushError {
2923+ type = ' ASSIGN_CONST_GLOBAL' ,
2924+ start = n .start ,
2925+ finish = n .finish ,
2926+ }
29452927 end
29462928 end
29472929 end
@@ -3223,21 +3205,10 @@ local function parseGlobal()
32233205 name .vstart = func .start
32243206 name .range = func .finish
32253207 func .parent = name
3226- name .isGlobalDecl = true
32273208 local gi = State .globalInfo
32283209 gi .active = true
32293210 local nameKey = name [1 ]
3230- local info = gi .names [nameKey ]
3231- if info and info .initialized then
3232- pushError {
3233- type = ' GLOBAL_DUPLICATE_INIT' ,
3234- start = name .start ,
3235- finish = name .finish ,
3236- }
3237- else
3238- gi .names [nameKey ] = gi .names [nameKey ] or { declared = true , const = false , initialized = false }
3239- gi .names [nameKey ].initialized = true
3240- end
3211+ gi .names [nameKey ] = gi .names [nameKey ] or { declared = true , const = false }
32413212 pushActionIntoCurrentChunk (name )
32423213 return name
32433214 else
@@ -3293,10 +3264,9 @@ local function parseGlobal()
32933264 finish = name .finish ,
32943265 [1 ] = name [1 ],
32953266 }
3296- glob .isGlobalDecl = true
32973267 local gi = State .globalInfo
32983268 gi .active = true
3299- gi .names [glob [1 ]] = gi .names [glob [1 ]] or { declared = true , const = false , initialized = false }
3269+ gi .names [glob [1 ]] = gi .names [glob [1 ]] or { declared = true , const = false }
33003270
33013271 if attrs then
33023272 glob .attrs = attrs
@@ -3356,8 +3326,7 @@ local function parseGlobal()
33563326 finish = nameN .finish ,
33573327 [1 ] = nameN [1 ],
33583328 }
3359- gN .isGlobalDecl = true
3360- gi .names [gN [1 ]] = gi .names [gN [1 ]] or { declared = true , const = false , initialized = false }
3329+ gi .names [gN [1 ]] = gi .names [gN [1 ]] or { declared = true , const = false }
33613330 if attrsN then
33623331 gN .attrs = attrsN
33633332 attrsN .parent = gN
@@ -4406,7 +4375,7 @@ local function initState(lua, version, options)
44064375 end
44074376 -- Lua 5.5 global keyword semantic tracking (syntax-level errors)
44084377 state .globalInfo = {
4409- names = {}, -- map name -> { declared=true, const=bool, initialized=bool }
4378+ names = {}, -- map name -> { declared=true, const=bool }
44104379 hasAll = false , -- global * encountered
44114380 allConst = false , -- global <const> * encountered
44124381 active = false , -- any global declaration activates strict global scope
0 commit comments