GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Void codemethod call should not crash by powercode · Pull Request #4850 · PowerShell/PowerShell

Conversation

@powercode

@powercode Staffan Gustafsson (powercode) commented Sep 16, 2017

Copy link
Copy Markdown
Collaborator

Fixes #4826

Adding a check if the method to be called is void, and in that case wrap it in a block that returns null.

Looking at some other code, there seems to be a CSharpBinderFlags.ResultDiscarded when they to this in C#. Can reviewers please check if this or something similar needs to be used here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Staffan Gustafsson added 2 commits September 16, 2017 09:36
Staffan Gustafsson
Failing test for calling void method
fe9f1c7
Staffan Gustafsson
Handling case in Invoking CodeMethod when return type is void.
06e20fe
@powercode
Staffan Gustafsson (powercode) requested review from Bruce Payette (BrucePay), Dongbo Wang (daxian-dbw), Jason Shirk (lzybkr) and sergei (vors) as code owners September 16, 2017 07:56
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-already-signed label Sep 16, 2017
lzybkr
Jason Shirk (lzybkr) suggested changes Sep 17, 2017
View reviewed changes

@lzybkr Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

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.

Just one small change and I think it's good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/runtime/Binding/Binders.cs Outdated
Expression expr = InvokeMethod(codeMethod.CodeReference, null, args.Prepend(target).ToArray(), false, MethodInvocationType.Ordinary);
if (codeMethod.CodeReference.ReturnType == typeof(void))
{
expr = Expression.Block(expr, Expression.Default(typeof(object)));

@lzybkr Jason Shirk (lzybkr) Sep 17, 2017

Copy link
Copy Markdown
Contributor

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.

This should be:

                    expr = Expression.Block(expr, ExpressionCache.AutomationNullConstant);

Otherwise it might be possible to use the return value.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Staffan Gustafsson
Addressing lzybkr review comments
f0ad5f8
@daxian-dbw Dongbo Wang (daxian-dbw) assigned Jason Shirk (lzybkr) Sep 18, 2017
lzybkr
Jason Shirk (lzybkr) approved these changes Sep 18, 2017
View reviewed changes
@lzybkr
Jason Shirk (lzybkr) merged commit 916ef56 into PowerShell:master Sep 20, 2017
@vors
sergei (vors) removed their request for review September 25, 2017 00:33
@powercode
Staffan Gustafsson (powercode) deleted the void_codemethod branch January 26, 2018 19:04
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Staffan Gustafsson @lzybkr
Call to CodeMethod returning void should work (PowerShell#4850)
5aeef45
Fixes PowerShell#4826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
1 more reviewer
@lzybkr Jason Shirk (lzybkr) lzybkr approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@lzybkr Jason Shirk (lzybkr)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@powercode @lzybkr @msftclas
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.