summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/operator.lua8
-rw-r--r--test/type_inference/init.lua20
2 files changed, 28 insertions, 0 deletions
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index e71911f9..9a8e255d 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -52,6 +52,14 @@ local function checkOperators(operators, op, value, result)
or not operator.extends then
goto CONTINUE
end
+ if value and operator.exp then
+ local valueNode = vm.compileNode(value)
+ local expNode = vm.compileNode(operator.exp)
+ local uri = guide.getUri(operator)
+ if not vm.isSubType(uri, valueNode, expNode) then
+ goto CONTINUE
+ end
+ end
if not result then
result = vm.createNode()
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 7bb39f19..619d7615 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3535,3 +3535,23 @@ TEST 'A' [[
local a
local <?b?> = a .. 1
]]
+
+TEST 'A' [[
+---@class A
+---@operator add(boolean): boolean
+---@operator add(integer): A
+
+---@type A
+local a
+local <?b?> = a + 1
+]]
+
+TEST 'boolean' [[
+---@class A
+---@operator add(boolean): boolean
+---@operator add(integer): A
+
+---@type A
+local a
+local <?b?> = a + true
+]]