From 76b8cf3236db2efc7f73f3508212d99199b73b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 30 Jan 2023 20:04:02 +0800 Subject: limit error message for type dismatch resolve #1838 --- script/vm/infer.lua | 9 +++++++++ script/vm/ref.lua | 3 +++ script/vm/type.lua | 22 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'script') diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 0b20700c..2f482116 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -11,6 +11,7 @@ local vm = require 'vm.vm' ---@field _lastView? string ---@field _lastViewUri? uri ---@field _lastViewDefault? any +---@field _subViews? string[] local mt = {} mt.__index = mt mt._hasTable = false @@ -413,6 +414,7 @@ function mt:view(uri, default) end local array = {} + self._subViews = array for view in pairs(self.views) do if not self._drop[view] then array[#array+1] = view @@ -471,6 +473,13 @@ function mt:eachView(uri) return next, self.views end +---@param uri uri +---@return string[] +function mt:getSubViews(uri) + self:view(uri) + return self._subViews +end + ---@return string? function mt:viewLiterals() if not self.node then diff --git a/script/vm/ref.lua b/script/vm/ref.lua index ba9bf453..b6760493 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -29,7 +29,10 @@ simpleSwitch = util.switch() ---@async local function searchInAllFiles(suri, searcher, notify) + await.delay() + searcher(suri) + await.delay() local uris = {} for uri in files.eachFile(suri) do diff --git a/script/vm/type.lua b/script/vm/type.lua index d01ca020..756926ba 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -301,7 +301,9 @@ function vm.isSubType(uri, child, parent, mark, errs) end end if hasKnownType > 0 then - if errs and hasKnownType > 1 then + if errs + and hasKnownType > 1 + and #vm.getInfer(child):getSubViews(uri) > 1 then errs[#errs+1] = 'TYPE_ERROR_CHILD_ALL_DISMATCH' errs[#errs+1] = child errs[#errs+1] = parent @@ -376,7 +378,9 @@ function vm.isSubType(uri, child, parent, mark, errs) end end if hasKnownType > 0 then - if errs and hasKnownType > 1 then + if errs + and hasKnownType > 1 + and #vm.getInfer(parent):getSubViews(uri) > 1 then errs[#errs+1] = 'TYPE_ERROR_PARENT_ALL_DISMATCH' errs[#errs+1] = child errs[#errs+1] = parent @@ -703,6 +707,7 @@ local ErrorMessageMap = { ---@return string function vm.viewTypeErrorMessage(uri, errs) local lines = {} + local mark = {} local index = 1 while true do local name = errs[index] @@ -741,8 +746,17 @@ function vm.viewTypeErrorMessage(uri, errs) index = index + 1 end local line = lang.script(name, lparams) - lines[#lines+1] = '- ' .. line + if not mark[line] then + mark[line] = true + lines[#lines+1] = '- ' .. line + end end util.revertTable(lines) - return table.concat(lines, '\n') + if #lines > 15 then + lines[13] = ('...(+%d)'):format(#lines - 15) + table.move(lines, #lines - 2, #lines, 14) + return table.concat(lines, '\n', 1, 16) + else + return table.concat(lines, '\n') + end end -- cgit v1.2.3