Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New solver] Function overload usage missing type error, but equivalent type function fine #1646

Open
Ketasaja opened this issue Feb 10, 2025 · 0 comments
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@Ketasaja
Copy link
Contributor

Ketasaja commented Feb 10, 2025

Luau 0.658
No error when calling a function with an invalid overload, but I expect an error.

I think all arguments to the overload need to be individually correct, so nset(c1, true) will error because there is no overload with a 2nd argument boolean.

--!strict
type nset = (component_1, component_1) -> () & 
(component_2, component_2) -> ()
local nset : nset
type component_1 = string
type component_2 = number

local c1: string
nset(c1, 1) -- Should error but doesn't, invalid overload
--[[
	local nset: ((number, number) -> ())
	& ((string, string) -> ())
]]

But the equivalent type function does error as expected:

--!strict
type component_1 = string
type component_2 = number

type function s(components)
    local intersection = nil

    local function add(component)
        local newfunction = types.newfunction({
            head = {
                component,
                component,
            }
        })
        intersection = if intersection then types.intersectionof(intersection, newfunction) else newfunction
    end

    if components:is("union") then
        for _, component in components:components() do
            add(component)
        end
    else
        add(components)
    end

    if intersection then
        return intersection
    else
        return types.singleton(nil)
    end
end

local c1: string
local mset: s<component_1 | component_2>
mset(c1, 1) -- Fine, TypeError: None of the overloads for function that accept 2 arguments are compatible.
--[[
	local mset: ((number, number) -> ())
	& ((string, string) -> ())
]]
@Ketasaja Ketasaja added the bug Something isn't working label Feb 10, 2025
@aatxe aatxe added the new solver This issue is specific to the new solver. label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.
Development

No branches or pull requests

2 participants