Skip to content

Conversation

@vexx32
Copy link
Collaborator

@vexx32 vexx32 commented Sep 18, 2018

PR Summary

This has been split off of #7509 at request of @iSazonov as that PR has become overly complex, and this portion of the PR was already approved by Powershell Committee. Re-submitting instead of working with #7575 due to messy rebase shenanigans that just... made a mess.

This fixes #3313.

Brief summary:

Adds the following numeric literal suffixes:

  • 'u' suffix (uint/ulong)
  • 's' suffix (short)
  • 'ul' suffix (ulong)
  • 'us' suffix (ushort)

Adds the following type accelerators:

  • [short]
  • [ushort]
  • [uint]
  • [ulong]

And of course, adds tests for all the above.

Comprehensive Summary:

  • Implements type suffixes s (short) and u (unsigned) to complement the existing l suffix.
    • Suffixes can be combined as us or ul to result in ushort or ulong types.
  • When u suffix is used alone, uint will be returned unless value exceeds uint.MaxValue, in which case it will automatically resolve as ulong instead.
  • Adds new type accelerators to fit new numeric types better into the PS ecosystem:
    • [short] => Int16
    • [ushort] => UInt16
    • [uint] => UInt32
    • [ulong] => UInt64
  • Maintains parity with existing l / L suffix, where it will also perform rounding functions when applied to a real literal while also ensuring it still returns an appropriate uint or ulong value: 105.5u => 106
  • Defines a new [Flags] enum NumberSuffixFlags that takes care of one-or-more numerical type suffixes.
  • Use of u, l, s and valid combinations thereof will error out and register as an invalid numeric literal if their value after multiplication exceeds the type(s) contraints.
    • This is intentional; if the user specifies a value that cannot be satisfied, such as 500sgb (500gb -as Int16)then the parser should not be expected to figure out what they meant.
  • Changes strNum parameter of TryGetNumberValue to ReadOnlySpan<char> to reduce the number of string allocations required for parsing.

PR Checklist

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 18, 2018

@iSazonov I think this is tidier now. shudders I need to take a rebasing class! 😝

The remaining build errors appear to be build environment errors unrelated to this PR. ^^

The CodeFactor issues are (I think) not particularly serious, and I have a follow-up PR that will address the vast majority of those coming shortly.

@iSazonov
Copy link
Collaborator

@vexx32 To rebase you can use the pattern:

# rebase pull request on top of master
git chechout <branch>
git fetch PowerShell master
git pull --rebase PowerShell master
git push -f

You can catch a conflict but it is another story.

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 19, 2018

Reopened to restart CIs. Looks all good, I guess the Linux issues were resolved.

@iSazonov I have never had the good fortune to get a rebase to work without painstaking editing at every step along the way. Not sure why... I think I must be doing it wrong somehow. I need to read up on it! 😄

@daxian-dbw daxian-dbw self-assigned this Sep 20, 2018
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@iSazonov
Copy link
Collaborator

@daxian-dbw Could you please look th PR? @vexx32 want to continue working on the code in follow PR.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

About the comments regarding the tests, I think it makes sense to keep some of the existing tests. They can be put only in the #Standard numeric notation section, not in other sections for the new notations.

@daxian-dbw daxian-dbw added the Breaking-Change breaking change that may affect users label Sep 27, 2018
@daxian-dbw
Copy link
Member

Marked this PR with Breaking-Change label. The new type suffix makes some command names be parsed as numbers now, for example:

function 100u { "Yay" }
100u

@daxian-dbw daxian-dbw added the Documentation Needed in this repo Documentation is needed in this repo label Sep 27, 2018
@daxian-dbw
Copy link
Member

@vexx32 I'm trying to tidy the PR description because the documentation work that follows up will need the accurate information.

'u' suffix (uint32)

By looking into the code, the suffix u doesn't guarantee uint32. It tries to fit the literal value into uin32 first, but if it fails, ulong will be used. Is taht implemetnation intentional? If so, please update the description.

I copied the Comprehensive Summary from #7509 as it's more relevant to this PR. But the summary is a little outdated compared with the implementation. Can you please update the summary? Thanks!

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 28, 2018

@daxian-dbw Yes, the automatic step-up to ulong is intentional. I felt that because u can be read simply as "unsigned" it makes the most sense to apply it in keeping with the existing patterns as best it can (i.e., a large integer currently will parse as long; thus, a large unsigned integer converts up to ulong when it exceeds uint32 bounds). I'll update the description and try to make sure everything fits with how it's intended to be. 😄

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 28, 2018

@daxian-dbw I think I got them all, but let me know if I missed anything! 😄

PR description has been cleaned up and made hopefully useful as a jumping off point for some proper documentation.

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 28, 2018

Aww, I was enjoying the all-green. Appveyor's failing on a Test-Connection due to timeout.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @vexx32 for your contribution! I will restart the AppVeyor CI.

@vexx32
Copy link
Collaborator Author

vexx32 commented Sep 28, 2018

Yay! 😄

Now I can get the next one ready for Hacktoberfest 😉

AppVeyor's still having difficulty with Test-Connection, it seems...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell doesn't understand unsigned numbers

5 participants