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 issue #13 'Single-element arrays are not preserved' #15

Merged
merged 1 commit into from
Dec 2, 2017

Conversation

vyrp
Copy link
Contributor

@vyrp vyrp commented Dec 2, 2017

In Powershell, if a function returns an array of only one element, it gets unwrapped. This is the root cause of issue #13.

This Pull Request fixes it by correctly returning the array.

Simple example:

function F($l) { return $l }

$result = F(@("a", "b"))
$result                     # a
                            # b
$result.GetType().Name      # Object[]
$result[0].GetType().Name   # String

$result = F(@("a"))
$result                     # a
$result.GetType().Name      # String (Ouch!)

$result = F(@())
$result                     #
$result.GetType().Name      # ERROR! You cannot call a method on a null-valued expression.
function Better-F($l) { return ,$l }

$result = Better-F(@("a", "b"))
$result                     # a
                            # b
$result.GetType().Name      # Object[]
$result[0].GetType().Name   # String

$result = Better-F(@("a"))
$result                     # a
$result.GetType().Name      # Object[] (FIXED!)
$result[0].GetType().Name   # String

$result = Better-F(@())
$result                     #
$result.GetType().Name      # Object[]

@Phil-Factor Phil-Factor merged commit 4a2756c into Phil-Factor:master Dec 2, 2017
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.

2 participants