Skip to content

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

Description

@GeeLaw

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions