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

Inference breaking when 2 parts is calling the same function #1414

Closed
ernisto opened this issue Sep 14, 2024 · 3 comments
Closed

Inference breaking when 2 parts is calling the same function #1414

ernisto opened this issue Sep 14, 2024 · 3 comments
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@ernisto
Copy link

ernisto commented Sep 14, 2024

This error appear when i call the same function eval in another part of the code
image
image

isolated repro

local t = {}

type constructor<data, methods = {}, handler = data & methods> = typeof(setmetatable({}, {
    __call = function(_,p: data): handler return nil :: any end
}))

type evaluable<T> = (any) -> T|T
local function eval<T>(evaluable: evaluable<T>, wrong: any?): T
    return if typeof(evaluable) == 'function' then evaluable(wrong) else evaluable
end

function t.number(default: evaluable<number?>, min: number?, max: number?, step: number?): (number, constructor<number>)
    local self = {} :: any
    -- local meta = { __index = methods }

    return setmetatable(self :: any, {
        -- __newindex = methods,
        __call = function(n: any?)
            if typeof(n) ~= 'number' then return assert(eval(default, n)) end
            if min then n = math.max(min, n) end
            if max then n = math.min(max, n) end
            if step then n = n // step * step end
            return n
        end
    }), self
end
function t.string(default: evaluable<string?>, regex: string?): (string, constructor<string>)
    local self = {} :: any
    -- local meta = { __index = methods }

    return setmetatable(self :: any, {
        -- __newindex = methods,
        __call = function(text: any?)
            return if text == nil or regex and not text:match(regex) then assert(eval(default, text)) else text
        end
    }), self
end
@ernisto ernisto added the bug Something isn't working label Sep 14, 2024
@ernisto
Copy link
Author

ernisto commented Sep 14, 2024

bruh, i just fixed changing type evaluable to ```luau
type evaluable = T|(any) -> T

@vegorov-rbx vegorov-rbx added the new solver This issue is specific to the new solver. label Sep 16, 2024
@aatxe
Copy link
Collaborator

aatxe commented Sep 20, 2024

I'm fairly certain type evaluable<T> = (any) -> T|T is not parsing how you want it to. It should be parsing T | T as the return type there, but I believe you wanted ((any) -> T) | T instead. So, I believe this is just user error.

@ernisto ernisto closed this as completed Sep 20, 2024
@ernisto
Copy link
Author

ernisto commented Sep 20, 2024

i forgot to close, srr

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

3 participants