@@ -805,12 +805,16 @@ local function getVariable(name, pos)
805805 -- Find global in this chunk (globals don't have effect time, just find the last one)
806806 local globals = chunk .globals
807807 if globals then
808- for n = # globals , 1 , - 1 do
808+ for n = 1 , # globals do
809809 local glob = globals [n ]
810- if glob [1 ] == name then
811- resGlobal = glob
810+ if glob .effect > pos then
812811 break
813812 end
813+ if glob [1 ] == name then
814+ if not resGlobal or resGlobal .effect < glob .effect then
815+ resGlobal = glob
816+ end
817+ end
814818 end
815819 end
816820
@@ -865,6 +869,9 @@ local function linkGlobalToEnv(node, var)
865869 type = ' VARIABLE_NOT_DECLARED' ,
866870 start = node .start ,
867871 finish = node .finish ,
872+ info = {
873+ name = node [1 ],
874+ }
868875 }
869876 end
870877 end
@@ -873,13 +880,13 @@ local function linkGlobalToEnv(node, var)
873880 local env
874881 if State .version == ' Lua 5.5' then
875882 env = getVariable (State .ENVMode , node .start )
876- if env and env .type == ' global ' then
883+ if env and env .type == ' setglobal ' then
877884 pushError {
878- type = ' RUNTIME_ERROR ' ,
885+ type = ' ENV_IS_GLOBAL ' ,
879886 start = node .start ,
880887 finish = node .finish ,
881888 info = {
882- message = ' _ENV is global when accessing variable '
889+ name = node [ 1 ],
883890 }
884891 }
885892 end
906913local function createGlobalDeclare (obj , attrs )
907914 obj .type = ' setglobal'
908915 obj .declare = true
916+ obj .effect = obj .finish
909917
910918 if attrs then
911919 obj .attrs = attrs
@@ -3188,18 +3196,18 @@ local function parseMultiVars(n1, parser, isLocal)
31883196 end
31893197 end
31903198
3191- if isLocal then
3192- local effect = lastValue and lastValue .finish or lastVar .finish
3193- n1 .effect = effect
3194- if n2 then
3195- n2 .effect = effect
3196- end
3197- if nrest then
3198- for i = 1 , # nrest do
3199- nrest [i ].effect = effect
3200- end
3199+ local effect = lastValue and lastValue .finish or lastVar .finish
3200+ n1 .effect = effect
3201+ if n2 then
3202+ n2 .effect = effect
3203+ end
3204+ if nrest then
3205+ for i = 1 , # nrest do
3206+ nrest [i ].effect = effect
32013207 end
3208+ end
32023209
3210+ do
32033211 -- Lua 5.4: only one <close> attribute allowed across a local declaration
32043212 -- Lua 5.5: multiple <close> are allowed
32053213 if State .version == ' Lua 5.4' then
0 commit comments