-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Use PSCustomObject instead of PSObject for synthetic types. #25363
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -478,7 +478,7 @@ private static bool TryGetRepresentativeTypeNameFromValue(object value, out PSTy | |
| psobjectPropertyList.Add(new PSMemberNameAndType(property.Name, propertyTypeName, property.Value)); | ||
| } | ||
|
|
||
| type = PSSyntheticTypeName.Create(typeObject, psobjectPropertyList); | ||
| type = PSSyntheticTypeName.Create(typeof(PSCustomObject), psobjectPropertyList); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -915,7 +915,10 @@ object ICustomAstVisitor.VisitConvertExpression(ConvertExpressionAst convertExpr | |
| { | ||
| if (InferTypes(hashtableAst).FirstOrDefault() is PSSyntheticTypeName syntheticTypeName) | ||
| { | ||
| return new[] { PSSyntheticTypeName.Create(type, syntheticTypeName.Members) }; | ||
| var baseSyntheticType = convertExpressionAst.Type.TypeName.FullName.EqualsOrdinalIgnoreCase(nameof(PSCustomObject)) | ||
| ? typeof(PSCustomObject) | ||
| : typeof(Hashtable); | ||
| return new[] { PSSyntheticTypeName.Create(baseSyntheticType, syntheticTypeName.Members) }; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1780,7 +1783,7 @@ bool IsInPropertyArgument(object o) | |
| foreach (var t in InferTypes(previousPipelineElementAst)) | ||
| { | ||
| var list = GetMemberNameAndTypeFromProperties(t, IsInPropertyArgument); | ||
| inferredTypes.Add(PSSyntheticTypeName.Create(typeof(PSObject), list)); | ||
| inferredTypes.Add(PSSyntheticTypeName.Create(typeof(PSCustomObject), list)); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1944,7 +1947,7 @@ private IEnumerable<PSTypeName> InferTypesFrom(MemberExpressionAst memberExpress | |
| var memberNameList = new List<string> { memberAsStringConst.Value }; | ||
| foreach (var type in exprType) | ||
| { | ||
| if (type.Type == typeof(PSObject) && type is not PSSyntheticTypeName) | ||
| if (type.Type == typeof(PSObject)) | ||
|
Comment on lines
-1947
to
+1950
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added that back in: #21184 so that it could get members for synthetic types but now that synthetic types aren't |
||
| { | ||
| continue; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above in lines 914 and 916 I see two Create() methods with 7 uses - all of them are subject to this change. Please describe all of them in the PR description (not only Hashtable). Perhaps they should also be reflected in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has already been described:
In other words, every instance where the synthetic type would say it's a "PSObject" has been updated to say it's a "PSCustomObject". This is in line with what we get at runtime, for example:
As for the specific overload references you mention, the first one is exclusively used for
Group-Objectwhere the specified typename isMicrosoft.PowerShell.Commands.GroupInfoso it's unaffected by these changes.The second overload is used by Select-Object, Hashtable type inference, and convert expressions where the target type is psobject/pscustomobject. This is where I've made a slight fix so that:
[psobject]@{Test = ls}is correctly treated as a hashtable, as the resulting object would just be a standard hashtable with an invisible psobject wrapper around it.Everything should already be covered by existing tests that were modified for this change, or added as part of the change.