-
Notifications
You must be signed in to change notification settings - Fork 349
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
Do not alter swift_versions
attribute when calculating Swift versions.
#592
Do not alter swift_versions
attribute when calculating Swift versions.
#592
Conversation
f1f63b4
to
2fc4003
Compare
first_hash['swift_version'].should == '5.0' | ||
spec_from_hash = Specification.from_hash(first_hash) | ||
second_hash = spec_from_hash.to_hash | ||
second_hash['swift_versions'].should == ['4.2', '5.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.
verified this fails without my actual change.
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.
Without the change this returns: ['4.2', '5.0', '5.0']
@@ -47,7 +47,7 @@ def swift_version | |||
# | |||
def swift_versions | |||
@swift_versions ||= begin | |||
swift_versions = Array(attributes_hash['swift_versions']) | |||
swift_versions = Array(attributes_hash['swift_versions']).dup |
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.
further below we do:
swift_versions << attributes_hash['swift_version'] unless attributes_hash['swift_version'].nil?
At this point swift_versions
points to the original array and it actually alters the internal structure of the specification.
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.
tbh I didn't realize this would ever alter the original structure. TIL.
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.
Yeap. Array()
doesn't make a new one if what we are parsing is already an array....🤦♂
@@ -47,7 +47,7 @@ def swift_version | |||
# | |||
def swift_versions | |||
@swift_versions ||= begin | |||
swift_versions = Array(attributes_hash['swift_versions']) | |||
swift_versions = Array(attributes_hash['swift_versions']).dup |
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.
tbh I didn't realize this would ever alter the original structure. TIL.
No description provided.