Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CoreAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ internal static MethodInformation FindBestMethod(
var parameterTypes = methodInfo.method.GetParameters().Select(parameter => parameter.ParameterType).ToArray();
var targetTypeMethod = invocationConstraints.MethodTargetType.GetMethod(methodInfo.method.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, parameterTypes, null);

if (targetTypeMethod != null && (targetTypeMethod.IsPublic || targetTypeMethod.IsFamily))
if (targetTypeMethod != null && (targetTypeMethod.IsPublic || targetTypeMethod.IsFamily || targetTypeMethod.IsFamilyOrAssembly))
{
methodInfo = new MethodInformation(targetTypeMethod, 0);
callNonVirtually = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,69 @@ Describe 'Classes methods with inheritance' -Tags "CI" {
[baz]::new().foo() | Should -Be 200600
}

It 'allows base class method call and doesn''t fall into recursion' {
It 'allows base .NET class method call and doesn''t fall into recursion' {
Add-Type -TypeDefinition @'
public class BaseMembersTestClass
{
public virtual int PublicMethod()
{
return 1001;
}

protected virtual int FamilyMethod()
{
return 2002;
}

protected internal virtual int FamilyOrAssemblyMethod()
{
return 3003;
}
}
'@
$derived = Invoke-Expression @'
class BaseCallTestClass : BaseMembersTestClass
{
hidden [int] $publicMethodCallCounter
[int] PublicMethod()
{
if ($this.publicMethodCallCounter++ -gt 0)
{
throw "Recursion happens"
}
return 3 * ([BaseMembersTestClass]$this).PublicMethod()
}

hidden [int] $familyMethodCallCounter
[int] FamilyMethod()
{
if ($this.familyMethodCallCounter++ -gt 0)
{
throw "Recursion happens"
}
return 3 * ([BaseMembersTestClass]$this).FamilyMethod()
}

hidden [int] $familyOrAssemblyMethodCallCounter
[int] FamilyOrAssemblyMethod()
{
if ($this.familyOrAssemblyMethodCallCounter++ -gt 0)
{
throw "Recursion happens"
}
return 3 * ([BaseMembersTestClass]$this).FamilyOrAssemblyMethod()
}
}

[BaseCallTestClass]::new()
'@

$derived.PublicMethod() | Should -Be 3003
$derived.FamilyMethod() | Should -Be 6006
$derived.FamilyOrAssemblyMethod() | Should -Be 9009
}

It 'allows base PowerShell class method call and doesn''t fall into recursion' {
class bar
{
[int]foo() {return 1001}
Expand Down