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
Use stricter rule to avoid unnecessary unwrapping of PSObject when operating on a COM object #4614
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d48d06
Use more restricted rule in general for DeferForPSObject
daxian-dbw 8e5392a
Use stricter rule only when needed
daxian-dbw 665e439
Add tests and touch up the comments
daxian-dbw 0ef2048
[Feature] Change '%' to 'ForEach-Object'
daxian-dbw f6ccde0
Address comments
daxian-dbw 2a90178
correct parameter names
daxian-dbw 772b3c8
Fix test -- setup test only if on windows desktop
daxian-dbw b2482a0
Address another comment
daxian-dbw 027c1d2
Make IsComObject a fater test
daxian-dbw 598e0b4
Remove unnecessary parenthesis
daxian-dbw File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here
expr
is not a PSObject, and IsComObject calls PSObject.BaseObject.A clean fix is to introduce an overload on IsComObject, one accepting PSObject and one that accepts object, calling the later here.
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.
The
IsComObject
method is also used inFallbackConvert
, and thattarget.Expression
there could represent eithera COM object or a PSObject wrapping a COM object. Are you suggesting to make the
expression restriction
a bit complex by changing it to'(target.expression is PSObject AND IsComObject(PSObject target.Expression)) OR (IsComObject(Object target.Expression))'
?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.
I think it's better to avoid the more complex version of
'expression restriction'
forFallbackConvert
. We can do one of the following two:OR
I vote for the first one.
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.
In that case, I vote for neither - I'd leave it or introduce another helper with a different name.
I tend to err on the side of less general code to get a faster test, but it probably doesn't matter much anyway.
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.
OK, I will leave the PR as is.
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.
Actually, we can have
IsComObject(PSObject)
andIsComObject(object)
, and make the'expression restriction'
inFallbackConvert
look like this:IsComObject(PSObject.Base(target.Expression))
, it makes the restriction a little bit more complex, but not much. I will go with it, let me know what you think.