Skip to content

Fix up default value for in parameters#26785

Merged
daxian-dbw merged 2 commits into
PowerShell:masterfrom
jborean93:default-value
Feb 18, 2026
Merged

Fix up default value for in parameters#26785
daxian-dbw merged 2 commits into
PowerShell:masterfrom
jborean93:default-value

Conversation

@jborean93
Copy link
Copy Markdown
Collaborator

PR Summary

Fix up calling a method with an in parameter modifier and the default value. Currently this only works for primitive types and default whereas other types need special handling to be called.

PR Context

Fixes: #26784

PR Checklist

Fix up calling a method with an `in` parameter modifier and the
`default` value. Currently this only works for primitive types and
`default` whereas other types need special handling to be called.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes PowerShell’s .NET method binder to correctly handle optional parameters declared with the in modifier when the default value is represented as null in metadata (e.g., in Guid x = default), avoiding expression tree construction errors for by-ref parameter types.

Changes:

  • Adjust binder logic to use the element type when building Expression.Default(...) for optional ByRef parameters.
  • Add CLR binding regression tests covering in + default for primitive, value, and reference types.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/powershell/engine/Basic/CLRBinding.Tests.ps1 Adds regression tests for invoking static methods with optional in parameters using default.
src/System.Management.Automation/engine/runtime/Binding/Binders.cs Updates optional-argument expression generation to avoid calling Expression.Default with a ByRef type.

Comment thread src/System.Management.Automation/engine/runtime/Binding/Binders.cs Outdated
…s.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TravisEz13 TravisEz13 added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Feb 13, 2026
Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@daxian-dbw daxian-dbw merged commit 1965e05 into PowerShell:master Feb 18, 2026
36 of 37 checks passed
@jborean93 jborean93 deleted the default-value branch February 18, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgumentException when calling Activity.AddException, due to in TagList tags = default parameter

4 participants