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

Fix singleton parameters in overloaded functions #1694

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

@m4fh m4fh marked this pull request as ready for review February 27, 2025 16:43
@m4fh
Copy link
Author

m4fh commented Feb 27, 2025

This code snippet is working now, and you get autocompletion with luau-lsp too (which was broken previously).

--[[
    local date: {
        day: number,
        hour: number,
        isdst: boolean,
        ... 6 more ...
    }
]]
local date = os.date("*t", 0)

Copy link
Collaborator

@aatxe aatxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just needs to be flagged properly! Thanks!

@m4fh
Copy link
Author

m4fh commented Mar 5, 2025

Thank you for the review! I think I’ve fixed it.

On a side note, while this does fix most of the issues I had with overloaded functions, I’ve noticed that it sometimes still doesn’t work. After some debugging, it seems that when a type alias or type function is used to 'create' the functions before intersecting them, fnType becomes a pending type (I don’t remember the exact name, to be honest). As a result, getExpectedCallTypesForFunctionOverloads can't determine the expected types.

I assume this could be fixed by somehow waiting for the type to resolve, but I’m not familiar enough with the codebase to know how to do that. I’d love to figure it out, and maybe there’s a simple approach I’m missing? No worries if not, I just wanted to make sure 😅

@aatxe
Copy link
Collaborator

aatxe commented Mar 5, 2025

Yeah, the change you've got here is to constraint generation, which is the first pass of the type inference system. Things like type aliases are not resolved yet, and many things have free or blocked types before inference starts to run. @hgoldstein has been working on a bunch of bidirectional typing stuff, and this should be in the same vein as that really. There'll need to be some work in constraint solving roughly equivalent in some way to what you've done here, but even fixing the constraint generation side of things for the cases where we can resolve things eagerly is a solid improvement.

@m4fh
Copy link
Author

m4fh commented Mar 5, 2025

Yeah, the change you've got here is to constraint generation, which is the first pass of the type inference system. Things like type aliases are not resolved yet, and many things have free or blocked types before inference starts to run. @hgoldstein has been working on a bunch of bidirectional typing stuff, and this should be in the same vein as that really. There'll need to be some work in constraint solving roughly equivalent in some way to what you've done here, but even fixing the constraint generation side of things for the cases where we can resolve things eagerly is a solid improvement.

I see, so I definitely bit off more than I could chew here 😅. Thank you for taking the time to explain it to me. I'm happy I could be of any help whatsoever.

@m4fh m4fh requested a review from aatxe March 7, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants