8000 Fix singleton parameters in overloaded functions by vvatheus · Pull Request #1694 · luau-lang/luau · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix singleton parameters in overloaded functions #1694

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

Merged

Conversation

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

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!

@vvatheus
Copy link
Contributor Author
vvatheus 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.

@vvatheus
Copy link
Contributor Author
vvatheus 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.

@vvatheus vvatheus requested a review from aatxe March 7, 2025 20:40
@aatxe aatxe merged commit 2621488 into luau-lang:master Mar 24, 2025
7 checks passed
@vvatheus vvatheus deleted the overloaded-functions-singleton-parameters branch March 28, 2025 21:38
ayoungbloodrbx added a commit that referenced this pull request Mar 28, 2025
After a very auspicious release last week, we have a new bevy of changes
for you!

## What's Changed

### Deprecated Attribute

This release includes an implementation of the `@deprecated` attribute
proposed in [this
RFC](https://rfcs.luau.org/syntax-attribute-functions-deprecated.html).
It relies on the new type solver to propagate deprecation information
from function and method AST nodes to the corresponding type objects.
These objects are queried by a linter pass when it encounters local,
global, or indexed variables, to issue deprecation warnings. Uses of
deprecated functions and methods in recursion are ignored. To support
deprecation of class methods, the parser has been extended to allow
attribute declarations on class methods. The implementation does not
support parameters, so it is not currently possible for users to
customize deprecation messages.

### General

- Add a limit for normalization of function types.

### New Type Solver

- Fix type checker to accept numbers as concat operands (Fixes #1671).
- Fix user-defined type functions failing when used inside type
aliases/nested calls (Fixes #1738, Fixes #1679).
- Improve constraint generation for overloaded functions (in part thanks
to @vvatheus in #1694).
- Improve type inference for indexers on table literals, especially when
passing table literals directly as a function call argument.
- Equate regular error type and intersection with a negation of an error
type.
- Avoid swapping types in 2-part union when RHS is optional.
- Use simplification when doing `~nil` refinements.
- `len<>` now works on metatables without `__len` function.

### AST

- Retain source information for `AstTypeUnion` and
`AstTypeIntersection`.

### Transpiler

- Print attributes on functions.

### Parser

- Allow types in indexers to begin with string literals by @jackdotink
in #1750.

### Autocomplete

- Evaluate user-defined type functions in ill-formed source code to
provide autocomplete.
- Fix the start location of functions that have attributes.
- Implement better fragment selection.

### Internal Contributors

Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Aviral Goel <agoel@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Sora Kanosue <skanosue@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>

**Full Changelog**:
0.666...0.667

---------

Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com>
Co-authored-by: Menarul Alam <malam@roblox.com>
Co-authored-by: Aviral Goel <agoel@roblox.com>
Co-authored-by: Vighnesh <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
0