From 54f1bac0815c0e51494f057282984d173469838f Mon Sep 17 00:00:00 2001 From: Tom Lau Date: Fri, 6 Sep 2024 11:18:20 +0800 Subject: test: add test cases for new overload type match behavior --- test/type_inference/param_match.lua | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/type_inference/param_match.lua b/test/type_inference/param_match.lua index 906b9305..21dcf4d3 100644 --- a/test/type_inference/param_match.lua +++ b/test/type_inference/param_match.lua @@ -172,6 +172,44 @@ local v = 'y' local = f(v) ]] +TEST 'string|number' [[ +---@overload fun(a: string) +---@overload fun(a: number) +local function f() end +]] + +TEST '1|2' [[ +---@overload fun(a: 1) +---@overload fun(a: 2) +local function f() end +]] + +TEST 'string' [[ +---@overload fun(a: 1): string +---@overload fun(a: 2): number +local function f(a) end + +local = f(1) +]] + +TEST 'number' [[ +---@overload fun(a: 1): string +---@overload fun(a: 2): number +local function f(a) end + +local = f(2) +]] + +TEST 'string|number' [[ +---@overload fun(a: 1): string +---@overload fun(a: 2): number +local function f(a) end + +---@type number +local v +local = f(v) +]] + TEST 'number' [[ ---@overload fun(a: 1, c: fun(x: number)) ---@overload fun(a: 2, c: fun(x: string)) -- cgit v1.2.3