-
Notifications
You must be signed in to change notification settings - Fork 391
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
Pre-populate/duplicate check class definitions (new solver) #1493
Conversation
This is another bug btw, error reporting is missing in |
Yeah, that's what I noticed. |
There's a test for this (class_definitions_reference_other_classes) which wasn't tripped by the new solver because of the |
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.
This needs to be flagged, but otherwise looks good.
flag gated |
db418c5
to
54e190a
Compare
if (!FFlag::LuauNewSolverPrePopulateClasses) | ||
continue; |
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.
we don't usually flag it this way, but honestly, it's kind of nice in this case.
Closes #1492
Tested and working with the test case in the aforementioned issue, along with the full defs of luau-lsp with no issues or type errors
In normal Luau files, you can use type aliases and type functions before they are declared. The same extends to declaration files, except in the new solver. The old solver perfectly allows this, and in fact intentionally adds it:
luau/Analysis/src/TypeInfer.cpp
Lines 1711 to 1717 in db80939
This causes much headache and pain for external projects that make use of declaration files; namely, luau-lsp generates them from MaximumADHD's API dump, which is not ordered by dependency. This means silent error-types popping up everywhere because types are used before they are declared. The workaround would be to make code to manually reorder class definitions based on their dependencies with a bunch of code, but this is clearly not ideal, and won't work for classes dependent on each other/recursive.
The solution used here is the same as is used for type aliases - the name binding for the class is given a blocked type before running the rest of constraint generation on the block. Questions remain:
checkAliases
?superTy
/parent
was bound, and several pieces of code assume it is not, so it had to be made followed.superTy
to setparent
the correct workaround for the assertions thrown, or should the code expectingparent
to be a ClassType without following it be modified instead to followparent
?scope->privateTypeBindings
also be checked for the duplicate error? I would presume so, since having a class with the same name as a private alias or type function should error as well?The extraneous whitespace changes are clang-format ones done automatically that should've been done in the last release - I can remove them if necessary and let another sync or OSS cleanup commit fix it.