ETS CodeMethod is always attempted even if the argument count is incorrect, and silently discards extra arguments

Open
#28,036 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp, powershell
Domain
backend, cli

Research direction

Start by running the PowerShell reproduction and compare the four observed results with the expected behavior. Trace the CodeMethod invocation and its argument-count handling, then find the existing tests for this entry point. Done means incorrect argument counts produce errors, while valid counts call the appropriate method without discarding extra arguments.

Written by the indexing model from the issue text.

Description

Needs-Triage
Prerequisites
Steps to reproduce
class Example
{
  static [string] Bar([psobject]$this_, [int]$first)
  {
    Return "Bar($first)";
  }
  [string] Foo([int]$first, [int]$second)
  {
    Return "Foo($first, $second)";
  }
}
Update-TypeData -TypeName ([Example].FullName) `
  -MemberType 'CodeMethod' -MemberName 'Foo' `
  -Value ([Example].GetMethod('Bar'));

Write-Verbose '[Example]::new().Foo()' -Verbose;
[Example]::new().Foo();

Write-Verbose '[Example]::new().Foo(1)' -Verbose;
[Example]::new().Foo(1);

Write-Verbose '[Example]::new().Foo(1, 2)' -Verbose;
[Example]::new().Foo(1, 2);

Write-Verbose '[Example]::new().Foo(1, 2, 3)' -Verbose;
[Example]::new().Foo(1, 2, 3);

Expected behavior
Error
Bar(1)
Foo(1, 2)
Error
Actual behavior
Error (cannot convert DBNull to int)
Bar(1)
Bar(1)
Bar(1)
Error details

No response

Environment data
Name                           Value
----                           -----
PSVersion                      7.6.6
PSEdition                      Core
GitCommitId                    7.6.6
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visuals

No response

Dominant language
C#
Stars
56.1k
Forks
8.5k
Avg merge
12h 33m
Merged PRs (30d)
73

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PowerShell/PowerShell

All issues in PowerShell/PowerShell

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.