2
2
local vm = require ' vm.vm'
3
3
local guide = require ' parser.guide'
4
4
local config = require ' config.config'
5
+ local util = require ' utility'
5
6
6
7
--- @param object vm.node.object
7
8
--- @return string ?
@@ -40,6 +41,51 @@ local function getNodeName(object)
40
41
return nil
41
42
end
42
43
44
+ --- @param parentName string
45
+ --- @param child vm.node.object
46
+ --- @param uri uri
47
+ --- @return boolean ?
48
+ local function checkEnum (parentName , child , uri )
49
+ local parentClass = vm .getGlobal (' type' , parentName )
50
+ if not parentClass then
51
+ return nil
52
+ end
53
+ for _ , set in ipairs (parentClass :getSets (uri )) do
54
+ if set .type == ' doc.enum' then
55
+ if child .type ~= ' string'
56
+ and child .type ~= ' doc.type.string'
57
+ and child .type ~= ' integer'
58
+ and child .type ~= ' number'
59
+ and child .type ~= ' doc.type.integer' then
60
+ return false
61
+ end
62
+ return util .arrayHas (set ._enums , child [1 ])
63
+ end
64
+ end
65
+
66
+ return nil
67
+ end
68
+
69
+ --- @param parent vm.node.object
70
+ --- @param child vm.node.object
71
+ --- @return boolean
72
+ local function checkValue (parent , child )
73
+ if parent .type == ' doc.type.integer' then
74
+ if child .type == ' integer'
75
+ or child .type == ' doc.type.integer'
76
+ or child .type == ' number' then
77
+ return parent [1 ] == child [1 ]
78
+ end
79
+ elseif parent .type == ' doc.type.string' then
80
+ if child .type == ' string'
81
+ or child .type == ' doc.type.string' then
82
+ return parent [1 ] == child [1 ]
83
+ end
84
+ end
85
+
86
+ return true
87
+ end
88
+
43
89
--- @param uri uri
44
90
--- @param child vm.node | string | vm.node.object
45
91
--- @param parent vm.node | string | vm.node.object
@@ -121,6 +167,9 @@ function vm.isSubType(uri, child, parent, mark)
121
167
end
122
168
123
169
if childName == parentName then
170
+ if not checkValue (parent , child ) then
171
+ return false
172
+ end
124
173
return true
125
174
end
126
175
@@ -144,6 +193,11 @@ function vm.isSubType(uri, child, parent, mark)
144
193
return true
145
194
end
146
195
196
+ local isEnum = checkEnum (parentName , child , uri )
197
+ if isEnum ~= nil then
198
+ return isEnum
199
+ end
200
+
147
201
-- TODO: check duck
148
202
if parentName == ' table' and not guide .isBasicType (childName ) then
149
203
return true
0 commit comments