Fixing HashMap to PSCustomObject object conversion (#2295)#2533
Fixing HashMap to PSCustomObject object conversion (#2295)#2533lzybkr merged 2 commits intoPowerShell:masterPowerShell/PowerShell:masterfrom charub:hashmap-to-pscustomobject-conversion-fixcharub/PowerShell:hashmap-to-pscustomobject-conversion-fixCopy head branch name to clipboard
Conversation
|
Hi @charub, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
vors
left a comment
There was a problem hiding this comment.
I'd also love to see more tests:
- ctor call with new() on type accelerator, on full type name
- ctor call with New-Object with full name, short name
- hashtable cast to full name
There was a problem hiding this comment.
Not sure about that: System.Management.Automation.PSCustomObject is a different type from System.Management.Automation.PSObject which we construct. Did you have a chance to figure out what's the difference between them?
There was a problem hiding this comment.
Don't need this change anymore. Only fixing the tab completion for 'pscu'
There was a problem hiding this comment.
We should avoid duplicated code, consider create a helper function.
There was a problem hiding this comment.
Don't need this change anymore. Only fixing the tab completion for 'pscu'
There was a problem hiding this comment.
I could be wrong, but it seems inconsistent with the current proposed conversion: the acelerator is for type PSCustomObject, but binder for hashtable does the conversion to PSObject. One option would be to completely eliminate PSCustomObject and set type accelerator to PSObject, if that doesn't break anything.
There was a problem hiding this comment.
This is a breaking change. I realize it feels wrong, but it's been this way since V1, we can't really change it.
There was a problem hiding this comment.
Don't need this change anymore.
lzybkr
left a comment
There was a problem hiding this comment.
I do question why anybody would want to use [System.Management.Automation.PSCustomObject]@{}.
If it only comes up because of tab completion, maybe we should special case tab completion of [pscustomobject].
There was a problem hiding this comment.
This is a breaking change. I realize it feels wrong, but it's been this way since V1, we can't really change it.
65527df to
677bc79
Compare
|
It seems the problem is the tab completion for pscu. 'PSCU' expands to [System.Management.Automation.PSCustomObject] when it should actually expand to [pscustomobject] which is an accelerator for System.Management.Automation.PSObject. |
|
Ok, that sounds reasonable: if we just fix IntelliSense then we will probably avoid most of the problems. |
|
This change seems fine (and necessary) to me, but perhaps it's not sufficient to fix the ambiguity that comes up in PSReadline. We definitely want some tests. It does fix more than Intellisense, e.g. if a method used PSCustomObject in it's signature, this change will affect the output of Get-Member. |
|
@charub please add some tests and we will merge it. |
677bc79 to
374fd88
Compare
There was a problem hiding this comment.
I would argue about correctness of this test.
It's a current behavior, but it's not the right one.
Maybe just drop the check for count and check for [1] == psobject and leave a comment explaining what's going on?
There was a problem hiding this comment.
As per the current behavior, pscu expands to System.Management.Automation.PSCustomObject. After this change, it will now expand to pscustomobject and psobject. both of these accelerators refer to System.Management.Automation.PSObject. I am afraid I don't understand your concern here.
There was a problem hiding this comment.
Is expanding to both psobject and pscustomobject a correct behavior for [pscu?
I don't think so. I think it should be pscustomobject only, because psobject doesn't start with pscu.
Why then make a test that verifies a wrong behavior?
There was a problem hiding this comment.
I think it's the correct behavior considering both are accelerators for [System.Management.Automation.PSObject].
There was a problem hiding this comment.
empty hashtable or $null
This test is only for $null
Can you one more testcase for empty hashtable?
There was a problem hiding this comment.
Added another test for an empty hashtable
There was a problem hiding this comment.
fail to create object
Any object? -Property $null seems like a special case.
Again the same question: is it the right test or it's just the current behavior.
There was a problem hiding this comment.
you are right. Corrected the test.
374fd88 to
01cf2c4
Compare
|
I'm currently waiting on the |
01cf2c4 to
124114e
Compare
|
@vors : You are right, pscu should only expand to pscustomobject and not psobject. Fixed the current behavior for tab completion when a type has more than 1 accelerators. |
Resolving PowerShell#2295 Fixing the current behavior of tab completion for types with more than 1 type accelerator.
124114e to
ed6a8ae
Compare
| } | ||
|
|
||
| internal static string FindBuiltinAccelerator(Type type) | ||
| internal static string FindBuiltinAccelerator(Type type,string expectedKey=null) |
There was a problem hiding this comment.
Style:
- space after comma,
- spaces around
=
| $errorObj = $_ | ||
| } | ||
| $obj | should be $null | ||
| $errorObj.FullyQualifiedErrorId | should be "CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand" |
There was a problem hiding this comment.
Should we add a follow-up item on that to completely remove this type?
cc @lzybkr
There was a problem hiding this comment.
It's probably not worth the hassle - it's a public api and hence a breaking change, and there is one valid use of the type (though that use can be expressed differently).
vors
left a comment
There was a problem hiding this comment.
Please, correct the style comments and it will be good for merge
Type completion would behave strangely when there were multiple aliases for a given type (currently only possible with type accelerators). The fix is to only select the accelerator that matches what the user typed. Closes PowerShell#2295
Fixing following issues :
After the fix, these 3 should not happen.