This repository was archived by the owner on Apr 29, 2025. It is now read-only.
fix(table): Respect falsy value for addDuplicateNumbers#672
Merged
thelindat merged 3 commits intooverextended:masterfrom Jan 16, 2025
tom-osborne:master
Merged
fix(table): Respect falsy value for addDuplicateNumbers#672thelindat merged 3 commits intooverextended:masterfrom tom-osborne:master
thelindat merged 3 commits intooverextended:masterfrom
tom-osborne:master
Conversation
Contributor
Author
|
See also #671 |
jag3dagster
approved these changes
Jan 16, 2025
Collaborator
jag3dagster
left a comment
There was a problem hiding this comment.
Logic checks out @thelindat
Collaborator
|
Thank you for the detailed explanation @tom-osborne |
thelindat
suggested changes
Jan 16, 2025
imports/table/shared.lua
Outdated
| ---Merges two tables together. Defaults to adding duplicate keys together if they are numbers, otherwise they are overriden. | ||
| local function table_merge(t1, t2, addDuplicateNumbers) | ||
| addDuplicateNumbers = addDuplicateNumbers ~= nil and addDuplicateNumbers or true | ||
| addDuplicateNumbers = addDuplicateNumbers == nil and true or addDuplicateNumbers |
Member
There was a problem hiding this comment.
addDuplicateNumbers = addDuplicateNumbers == nil or addDuplicateNumbers
Contributor
Author
There was a problem hiding this comment.
@thelindat Changes made as requested. Thanks
abdel1touimi
pushed a commit
to SaharaScripters/ox_lib
that referenced
this pull request
Jan 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The logic for the third parameter (
addDuplicateNumbers) does not respect a falsy value.When a value of
falseis passed the logic is resolved as follows:addDuplicateNumbers ~= nilresolves totrueaddDuplicateNumbers ~= nil and addDuplicateNumbersis therefore the same astrue and falsewhich resolves tofalseaddDuplicateNumbers ~= nil and addDuplicateNumbers or trueis therefore the same afalse or true, which resolves totrueSo a falsy value always coerces to
true.Simple test script:
Proposed solution is to reverse the logic somewhat so it sets the value to
trueonly whennil.Running the same test script: