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

Fix sort ordering logic #696

Closed
wants to merge 3 commits into from

Conversation

MidnightLightning
Copy link

Having two separate sort calls doesn't actually preserve the ordering of the first sort (by name) so only the second (constant vs. not) was being sorted on properly. This fix first checks to see if the two items have different constant values, and only if their constant values are the same does it then sort by name.

@yann300
Copy link
Collaborator

yann300 commented Aug 17, 2017

thanks for that! we will push it.
a little thing: a.name can be undefined (if constructor) so it need to be tested.

// If we reach here, either a and b are both constant or both not; sort by name then
// special case for fallback and constructor
if (a.type === 'function') {
return a.name.localeCompare(b.name)
Copy link
Member

Choose a reason for hiding this comment

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

Hm, this shouldn't be locale specific I think. Also identifiers can be ASCII only.

Copy link
Author

Choose a reason for hiding this comment

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

localeCompare() is the only native string-comparison function in Javascript; would you rather multiple separate calls to check greater, less, and equal?

Copy link
Member

Choose a reason for hiding this comment

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

Since this is only used for display purposes it should be fine, though I'd add a comment.

If this would be critical piece of code, either:

  • a manual implementation
  • or setting the locale to ASCII English upfront

would be needed, because certain languages consider di/trigraphs with different sorting order.

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Please add a case for a.name === undefined (case for fallback/constructor).

@axic
Copy link
Member

axic commented Dec 18, 2017

@MidnightLightning are you interested in finishing this? Would be a good feature to merge.

@MidnightLightning
Copy link
Author

@axic Thanks for the reminder; updated now!

@yann300
Copy link
Collaborator

yann300 commented Dec 18, 2017

@MidnightLightning could you rebase?

@MidnightLightning
Copy link
Author

@yann300 Rebased now.

@yann300
Copy link
Collaborator

yann300 commented Dec 18, 2017

sorry, there are some standard errors:

standard: Run `standard --fix` to automatically fix some problems.
  /home/travis/build/ethereum/browser-solidity/src/app/execution/txHelper.js:37:17: Extra semicolon.
  /home/travis/build/ethereum/browser-solidity/src/app/execution/txHelper.js:39:18: Extra semicolon.
  /home/travis/build/ethereum/browser-solidity/src/app/execution/txHelper.js:49:5: Unreachable code.
  /home/travis/build/ethereum/browser-solidity/src/app/execution/txHelper.js:49:12: 'abi' is not defined.

@MidnightLightning
Copy link
Author

@yann300 Coding standard errors fixed now.

@yann300
Copy link
Collaborator

yann300 commented Dec 19, 2017

great! thanks

@MidnightLightning
Copy link
Author

@yann300 Any further changes needed on this one? GitHub's still indicating you as a reviewer have changes requested.

@@ -32,20 +32,20 @@ module.exports = {
},

sortAbiFunction: function (contractabi) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment above here explaining the order? e.g. constructor, fallback, constant functions, non-constant functions?

Copy link
Author

Choose a reason for hiding this comment

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

@axic Okay, added now.

@axic
Copy link
Member

axic commented Feb 26, 2018

@yann300 anything left on this?

@yann300
Copy link
Collaborator

yann300 commented Feb 26, 2018

moved, thanks @MidnightLightning

@yann300 yann300 closed this Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants