summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/vm.lua21
-rw-r--r--server/test/definition/method.lua50
2 files changed, 38 insertions, 33 deletions
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 004e40f9..69aa4a43 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -707,6 +707,7 @@ function mt:getName(name, source)
if loc then
return loc
end
+ source.uri = self.uri
local ENV = self.scope.locals._ENV
local ENVValue = self:getValue(ENV)
local global = ENVValue:getField(name, source) or ENVValue:createField(name, source)
@@ -841,11 +842,15 @@ function mt:getSimple(simple, mode)
elseif tp == 'index' then
local child = obj[1]
local index = self:getIndex(child)
- field = value:getField(index, child) or value:createField(index, child)
- field.parentValue = value
- value = self:getValue(field)
if mode == 'value' or i < #simple then
+ field = value:getField(index, child) or value:createField(index, child)
+ field.parentValue = value
+ value = self:getValue(field)
self:addInfo(field, 'get', obj)
+ else
+ field = value:createField(index, child)
+ field.parentValue = value
+ value = self:getValue(field)
end
field.parent = lastField
lastField = field
@@ -859,11 +864,15 @@ function mt:getSimple(simple, mode)
parentName = ('%s[?]'):format(parentName)
end
elseif tp == 'name' then
- field = value:getField(obj[1], obj) or value:createField(obj[1], obj)
- field.parentValue = value
- value = self:getValue(field)
if mode == 'value' or i < #simple then
+ field = value:getField(obj[1], obj) or value:createField(obj[1], obj)
+ field.parentValue = value
+ value = self:getValue(field)
self:addInfo(field, 'get', obj)
+ else
+ field = value:createField(obj[1], obj)
+ field.parentValue = value
+ value = self:getValue(field)
end
field.parent = lastField
lastField = field
diff --git a/server/test/definition/method.lua b/server/test/definition/method.lua
index 7db4b56d..40c5f127 100644
--- a/server/test/definition/method.lua
+++ b/server/test/definition/method.lua
@@ -112,30 +112,26 @@ local obj = sm({}, mt)
obj:<?method1?>()
]]
--- TODO 更换 meta__index 的实现
--- 表和__index之间不共享child
--- 编译完成后进行后处理,如果某个field只有读取操作,则将值链接到meta表中
-
---TEST [[
---local mt = {}
---function mt:<!x!>()
---end
---
---local obj = setmetatable({}, {__index = mt})
---function obj:x()
---end
---
---mt:<?x?>()
---]]
---
---TEST [[
---local mt = {}
---function mt:x()
---end
---
---local obj = setmetatable({}, {__index = mt})
---function obj:<!x!>()
---end
---
---obj:<?x?>()
---]]
+TEST [[
+local mt = {}
+function mt:<!x!>()
+end
+
+local obj = setmetatable({}, {__index = mt})
+function obj:x()
+end
+
+mt:<?x?>()
+]]
+
+TEST [[
+local mt = {}
+function mt:x()
+end
+
+local obj = setmetatable({}, {__index = mt})
+function obj:<!x!>()
+end
+
+obj:<?x?>()
+]]