Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: large unions no longer erroneously fail to match later variants #3208

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
sumneko merged 1 commit into LuaLS:master from DoubleThoughtTheProgrammer:large-unions
Jun 25, 2025

Conversation

Copy link
Contributor

@DoubleThoughtTheProgrammer DoubleThoughtTheProgrammer commented Jun 22, 2025
edited
Loading

Close #3178 and close #3126 by adding a config option Lua.type.maxUnionVariants to control how many union variants a value is checked against. By default, the setting is set to 0, meaning that the language server will check all union variants.

Further work to improve ergonomics with this setting might include adding a warning when a union type is defined that has too many variants.

tomlau10 and cprn reacted with thumbs up emoji
Copy link
Contributor

I think you can also link #3126 in your pr description, as they are essentially the same issue 👀

Close #3178 and close #3126 by adding ...

=> so both issues can be closed automatically when this pr is merged

Copy link
Contributor Author

DoubleThoughtTheProgrammer commented Jun 22, 2025
edited
Loading

I think you can also link #3126 in your pr description, as they are essentially the same issue 👀

Thanks, I've edited the description to include that.

tomlau10 reacted with laugh emoji

@CppCXY CppCXY requested a review from Copilot June 22, 2025 11:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where large unions were failing to match later variants by introducing a configurable limit on the number of union variants checked. Key changes include:

  • Replacing the fixed union variant limit (100) with a dynamic check using the new config option Lua.type.maxUnionVariants.
  • Adding the new configuration option to the config template.
  • Updating the changelog to document these changes.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
script/vm/type.lua Updated union variant iteration logic to honor the new Lua.type.maxUnionVariants setting.
script/config/template.lua Added the new configuration option Lua.type.maxUnionVariants.
changelog.md Documented the fix and the new configuration option related to union variant checking.
Comments suppressed due to low confidence (1)

script/vm/type.lua:381

  • [nitpick] A short inline comment explaining the intent behind the 'maxUnionVariants' check could improve clarity for future maintainers.
 if maxUnionVariants > 0 and i > maxUnionVariants then

@@ -374,10 +374,11 @@ function vm.isSubType(uri, child, parent, mark, errs)
elseif child.type == 'vm.node' then
if config.get(uri, 'Lua.type.weakUnionCheck') then
local hasKnownType = 0
local maxUnionVariants = config.get(uri, 'Lua.type.maxUnionVariants') or 0
Copy link
Preview

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider refactoring to reduce duplication by extracting the retrieval of 'maxUnionVariants' to a helper function or common code block if similar logic appears in multiple branches.

Suggested change
local maxUnionVariants = config.get(uri, 'Lua.type.maxUnionVariants') or0
local maxUnionVariants = getMaxUnionVariants(uri)

Copilot uses AI. Check for mistakes.

TIMONz1535 reacted with thumbs down emoji
@@ -374,10 +374,11 @@ function vm.isSubType(uri, child, parent, mark, errs)
elseif child.type == 'vm.node' then
if config.get(uri, 'Lua.type.weakUnionCheck') then
local hasKnownType = 0
local maxUnionVariants = config.get(uri, 'Lua.type.maxUnionVariants') or 0
Copy link
Member

Choose a reason for hiding this comment

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

should default 100?

Copy link
Contributor Author

@DoubleThoughtTheProgrammer DoubleThoughtTheProgrammer Jun 23, 2025

Choose a reason for hiding this comment

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

I decided to change to default to no limit, because I think that the language server should prioritise correctness over performance by default. I think it should be up to the user to decide that they can afford to sacrifice correctness for performance. It's a lot more confusing for a user to see the language server giving an incorrect diagnostic by default (and then needing to figure out there's a setting to change the behaviour) than it would be for a user to see poor performance.

Quezler reacted with thumbs up emoji grillonbleu reacted with heart emoji
Copy link
Contributor Author

@DoubleThoughtTheProgrammer DoubleThoughtTheProgrammer Jun 23, 2025

Choose a reason for hiding this comment

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

More pertinently, this pull request wouldn't actually resolve the linked issues if the maximum value was left configured to 100.

@sumneko sumneko merged commit c8dd977 into LuaLS:master Jun 25, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@CppCXY CppCXY CppCXY left review comments

Copilot code review Copilot Copilot left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Incorrect diagnostics with large (~300 members) union LÖVE: False Warning on love.keyboard.isDown() Despite Valid KeyConstant

AltStyle によって変換されたページ (->オリジナル) /