summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--locale/en-us/script.lua6
-rw-r--r--locale/pt-br/script.lua6
-rw-r--r--locale/zh-cn/script.lua6
-rw-r--r--locale/zh-tw/script.lua6
-rw-r--r--script/vm/type.lua45
5 files changed, 44 insertions, 25 deletions
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index c9cb991c..9fceac00 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -609,10 +609,12 @@ TYPE_ERROR_TABLE_NO_FIELD =
'Field `{key}` does not exist in the table'
TYPE_ERROR_TABLE_FIELD_DISMATCH =
'The type of field `{key}` is `{child}`, which cannot match `{parent}`'
-TYPE_ERROR_UNION_ALL_DISMATCH =
+TYPE_ERROR_CHILD_ALL_DISMATCH =
'All subtypes in `{child}` cannot match `{parent}`'
+TYPE_ERROR_PARENT_ALL_DISMATCH =
+'`{child}` cannot match any subtypes in `{parent}`'
TYPE_ERROR_UNION_DISMATCH =
-'`{child}` in union type cannot match `{parent}`'
+'`{child}` cannot match `{parent}`'
TYPE_ERROR_OPTIONAL_DISMATCH =
'Optional type cannot match `{parent}`'
TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER =
diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua
index 8f01f949..a6adc651 100644
--- a/locale/pt-br/script.lua
+++ b/locale/pt-br/script.lua
@@ -609,10 +609,12 @@ TYPE_ERROR_TABLE_NO_FIELD = -- TODO: need translate!
'Field `{key}` does not exist in the table'
TYPE_ERROR_TABLE_FIELD_DISMATCH = -- TODO: need translate!
'The type of field `{key}` is `{child}`, which cannot match `{parent}`'
-TYPE_ERROR_UNION_ALL_DISMATCH = -- TODO: need translate!
+TYPE_ERROR_CHILD_ALL_DISMATCH = -- TODO: need translate!
'All subtypes in `{child}` cannot match `{parent}`'
+TYPE_ERROR_PARENT_ALL_DISMATCH = -- TODO: need translate!
+'`{child}` cannot match any subtypes in `{parent}`'
TYPE_ERROR_UNION_DISMATCH = -- TODO: need translate!
-'`{child}` in union type cannot match `{parent}`'
+'`{child}` cannot match `{parent}`'
TYPE_ERROR_OPTIONAL_DISMATCH = -- TODO: need translate!
'Optional type cannot match `{parent}`'
TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER = -- TODO: need translate!
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index 5c86a1d0..86815da3 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -609,10 +609,12 @@ TYPE_ERROR_TABLE_NO_FIELD =
'表中不存在字段 `{key}`'
TYPE_ERROR_TABLE_FIELD_DISMATCH =
'字段 `{key}` 的类型为 `{child}`,无法匹配 `{parent}`'
-TYPE_ERROR_UNION_ALL_DISMATCH =
+TYPE_ERROR_CHILD_ALL_DISMATCH =
'`{child}` 中的所有子类型均无法匹配 `{parent}`'
+TYPE_ERROR_PARENT_ALL_DISMATCH =
+'`{child}` 无法匹配 `{parent}` 中的任何子类'
TYPE_ERROR_UNION_DISMATCH =
-'联合类型中的 `{child}` 无法匹配 `{parent}`'
+'`{child}` 无法匹配 `{parent}`'
TYPE_ERROR_OPTIONAL_DISMATCH =
'可选类型无法匹配 `{parent}`'
TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER =
diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua
index 36615a05..060ae8ab 100644
--- a/locale/zh-tw/script.lua
+++ b/locale/zh-tw/script.lua
@@ -609,10 +609,12 @@ TYPE_ERROR_TABLE_NO_FIELD = -- TODO: need translate!
'Field `{key}` does not exist in the table'
TYPE_ERROR_TABLE_FIELD_DISMATCH = -- TODO: need translate!
'The type of field `{key}` is `{child}`, which cannot match `{parent}`'
-TYPE_ERROR_UNION_ALL_DISMATCH = -- TODO: need translate!
+TYPE_ERROR_CHILD_ALL_DISMATCH = -- TODO: need translate!
'All subtypes in `{child}` cannot match `{parent}`'
+TYPE_ERROR_PARENT_ALL_DISMATCH = -- TODO: need translate!
+'`{child}` cannot match any subtypes in `{parent}`'
TYPE_ERROR_UNION_DISMATCH = -- TODO: need translate!
-'`{child}` in union type cannot match `{parent}`'
+'`{child}` cannot match `{parent}`'
TYPE_ERROR_OPTIONAL_DISMATCH = -- TODO: need translate!
'Optional type cannot match `{parent}`'
TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER = -- TODO: need translate!
diff --git a/script/vm/type.lua b/script/vm/type.lua
index f481cf78..c60978e5 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -133,8 +133,8 @@ local function checkValue(parent, child, mark, err)
or child.type == 'number' then
if parent[1] ~= child[1] then
err[#err+1] = 'TYPE_ERROR_INTEGER_DISMATCH'
- err[#err+1] = child
- err[#err+1] = parent
+ err[#err+1] = child[1]
+ err[#err+1] = parent[1]
return false
end
end
@@ -148,8 +148,8 @@ local function checkValue(parent, child, mark, err)
or child.type == 'doc.field.name' then
if parent[1] ~= child[1] then
err[#err+1] = 'TYPE_ERROR_STRING_DISMATCH'
- err[#err+1] = child
- err[#err+1] = parent
+ err[#err+1] = child[1]
+ err[#err+1] = parent[1]
return false
end
end
@@ -161,8 +161,8 @@ local function checkValue(parent, child, mark, err)
or child.type == 'doc.type.boolean' then
if parent[1] ~= child[1] then
err[#err+1] = 'TYPE_ERROR_BOOLEAN_DISMATCH'
- err[#err+1] = child
- err[#err+1] = parent
+ err[#err+1] = child[1]
+ err[#err+1] = parent[1]
return false
end
end
@@ -234,19 +234,21 @@ function vm.isSubType(uri, child, parent, mark, err)
child = global
elseif child.type == 'vm.node' then
if config.get(uri, 'Lua.type.weakUnionCheck') then
- local hasKnownType
+ local hasKnownType = 0
for n in child:eachObject() do
if getNodeName(n) then
- hasKnownType = true
+ hasKnownType = hasKnownType + 1
if vm.isSubType(uri, n, parent, mark, err) == true then
return true, err
end
end
end
- if hasKnownType then
- err[#err+1] = 'TYPE_ERROR_UNION_ALL_DISMATCH'
- err[#err+1] = child
- err[#err+1] = parent
+ if hasKnownType > 0 then
+ if hasKnownType > 1 then
+ err[#err+1] = 'TYPE_ERROR_CHILD_ALL_DISMATCH'
+ err[#err+1] = child
+ err[#err+1] = parent
+ end
return false, err
end
return true, err
@@ -293,10 +295,10 @@ function vm.isSubType(uri, child, parent, mark, err)
end
parent = global
elseif parent.type == 'vm.node' then
- local hasKnownType
+ local hasKnownType = 0
for n in parent:eachObject() do
if getNodeName(n) then
- hasKnownType = true
+ hasKnownType = hasKnownType + 1
if vm.isSubType(uri, child, n, mark, err) == true then
return true, err
end
@@ -307,7 +309,15 @@ function vm.isSubType(uri, child, parent, mark, err)
return true, err
end
end
- return not hasKnownType, err
+ if hasKnownType > 0 then
+ if hasKnownType > 1 then
+ err[#err+1] = 'TYPE_ERROR_PARENT_ALL_DISMATCH'
+ err[#err+1] = child
+ err[#err+1] = parent
+ end
+ return false, err
+ end
+ return true, err
end
---@cast parent vm.node.object
@@ -342,7 +352,7 @@ function vm.isSubType(uri, child, parent, mark, err)
and child[1]
and not math.tointeger(child[1]) then
err[#err+1] = 'TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER'
- err[#err+1] = child
+ err[#err+1] = child[1]
return false, err
end
if child.type == 'global'
@@ -604,7 +614,8 @@ local ErrorMessageMap = {
TYPE_ERROR_BOOLEAN_DISMATCH = {'child', 'parent'},
TYPE_ERROR_TABLE_NO_FIELD = {'key'},
TYPE_ERROR_TABLE_FIELD_DISMATCH = {'key', 'child', 'parent'},
- TYPE_ERROR_UNION_ALL_DISMATCH = {'child', 'parent'},
+ TYPE_ERROR_CHILD_ALL_DISMATCH = {'child', 'parent'},
+ TYPE_ERROR_PARENT_ALL_DISMATCH = {'child', 'parent'},
TYPE_ERROR_UNION_DISMATCH = {'child', 'parent'},
TYPE_ERROR_OPTIONAL_DISMATCH = {'parent'},
TYPE_ERROR_NUMBER_LITERAL_TO_INTEGER = {'child'},