Skip to content
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

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

dnkoutso
Copy link
Contributor

No description provided.

@dnkoutso dnkoutso added this to the 1.8.1 milestone Sep 27, 2019
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']
Copy link
Contributor Author

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.

Copy link
Contributor Author

@dnkoutso dnkoutso Sep 27, 2019

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
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@dnkoutso dnkoutso Sep 27, 2019

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants