@@ -8,6 +8,7 @@ local util = require 'utility'
88--- @field package _casts ? parser.object[]
99
1010--- @class vm.tracer
11+ --- @field name string
1112--- @field source parser.object
1213--- @field assigns parser.object[]
1314--- @field assignMap table<parser.object , true>
@@ -30,7 +31,7 @@ function mt:getCasts()
3031 root ._casts = {}
3132 local docs = root .docs
3233 for _ , doc in ipairs (docs ) do
33- if doc .type == ' doc.cast' and doc .loc then
34+ if doc .type == ' doc.cast' and doc .name then
3435 root ._casts [# root ._casts + 1 ] = doc
3536 end
3637 end
@@ -113,10 +114,10 @@ function mt:collectLocal()
113114
114115 local casts = self :getCasts ()
115116 for _ , cast in ipairs (casts ) do
116- if cast .loc [1 ] == self .source [ 1 ]
117+ if cast .name [1 ] == self .name
117118 and cast .start > startPos
118119 and cast .finish < finishPos
119- and guide .getLocal (self .source , self .source [ 1 ] , cast .start ) == self .source then
120+ and guide .getLocal (self .source , self .name , cast .start ) == self .source then
120121 self .casts [# self .casts + 1 ] = cast
121122 end
122123 end
@@ -153,6 +154,17 @@ function mt:collectGlobal()
153154 finishPos = get .finish
154155 end
155156 end
157+
158+ local casts = self :getCasts ()
159+ for _ , cast in ipairs (casts ) do
160+ if cast .name [1 ] == self .name then
161+ self .casts [# self .casts + 1 ] = cast
162+ end
163+ end
164+
165+ if # self .casts > 0 then
166+ self .fastCalc = false
167+ end
156168end
157169
158170--- @param start integer
@@ -794,8 +806,10 @@ local function createTracer(source)
794806
795807 if source .type == ' local'
796808 or source .type == ' self' then
809+ tracer .name = source [1 ]
797810 tracer :collectLocal ()
798811 else
812+ tracer .name = source .global :getName ()
799813 tracer :collectGlobal ()
800814 end
801815
0 commit comments