-
Notifications
You must be signed in to change notification settings - Fork 425
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
Fix singleton parameters in overloaded functions #1694
Conversation
- Fixes Overloaded functions with singleton parameters error incorrectly in new type solver #1691
- Fixes String literals aren't refined to singleton types in function overloads #1589
…all_with_singletons_mismatch` in TypeInfer.singletons.test.cpp
I thought this test case was related, but I guess it's a different issue?
This code snippet is working now, and you get autocompletion with --[[
local date: {
day: number,
hour: number,
isdst: boolean,
... 6 more ...
}
]]
local date = os.date("*t", 0) |
There was a problem hiding this 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!
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, 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 😅 |
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. |
Co-authored-by: ariel <aweiss@hey.com>
Co-authored-by: ariel <aweiss@hey.com>
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. |
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>