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 type solver incorrectly infers function return type as number? #1399

Open
Daw588 opened this issue Sep 12, 2024 · 1 comment
Open

New type solver incorrectly infers function return type as number? #1399

Daw588 opened this issue Sep 12, 2024 · 1 comment
Labels
bug Something isn't working new solver This issue is specific to the new solver.

Comments

@Daw588
Copy link

Daw588 commented Sep 12, 2024

I expect GetValidRandomNumber to return number because the while loop will never exit unless the number is returned, but the solver infers that it returns number?.

local function IsValid(x)
    return x > 50
end

local function GetValidRandomNumber() -- number?
    while true do
        local id = math.random(100)
        if IsValid(id) then
            return id
        end
    end
end
@Daw588 Daw588 added the bug Something isn't working label Sep 12, 2024
@aatxe aatxe added the new solver This issue is specific to the new solver. label Sep 12, 2024
@YOUWILLDIE666
Copy link

YOUWILLDIE666 commented Sep 14, 2024

I don't think this is a bug... It's theoretically possible that the while true loop would run indefinitely and not return anything, but the probability of that happening is equivalent to the probability of the IsValid function always returning false for an infinite sequence of independent random numbers (which is lim (n → ∞) (1/2)n = 0, or speaking words, the probability of this event occurring is infinitesimally small). So the solver's infer is right?

(or it's just Luau being Luau I don't know ¯\_(ツ)_/¯)

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