Skip to content

Commit f8479a2

Browse files
committed
Fix recursion in inheritance check
Adds test for double derived class Fixes RH-37982
1 parent f309d31 commit f8479a2

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/Compat/Utils.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@ internal static bool IsDerived(TypeDefinition type, TypeReference base_type)
164164
return true;
165165
try
166166
{
167-
IsDerived(type.BaseType.Resolve(), base_type);
167+
return IsDerived(type.BaseType.Resolve(), base_type);
168168
}
169169
catch (AssemblyResolutionException)
170170
{
171171
return false;
172172
}
173-
return false;
174173
}
175174

176175
/// <summary>

test/integration/access.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,8 @@ function teardown {
118118

119119
# @test "should pass if public nested class becomes protected internal when called from derived class" {
120120
cat test_output | grep "✓ System.Void AccessTestLib.MyClass::PublicMethodBecomesProtectedInternal() < AccessTestLib"
121+
# }
122+
123+
# @test "should pass if protected method called from double derived class" {
124+
cat test_output | grep "✓ System.Void AccessTestLib.BaseClassWithProtectedVirtualMethod::ProtectedVirtualMethod() < AccessTestLib"
121125
}

test/integration/projects/AccessTest/AccessTest/MyClass.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
23
namespace AccessTest
34
{
45
public class MyClass
@@ -136,4 +137,18 @@ public DerivedClass()
136137
this.PublicMethodBecomesProtectedInternal();
137138
}
138139
}
140+
141+
// the case of the protected virtual method...
142+
// see RH-37982
143+
144+
class DerivedClassWithProtectedOverrideMethod : AccessTestLib.BaseClassWithProtectedVirtualMethod
145+
{ }
146+
147+
class DoubleDerivedClassWithProtectedOverrideMethod : DerivedClassWithProtectedOverrideMethod
148+
{
149+
protected override void ProtectedVirtualMethod()
150+
{
151+
base.ProtectedVirtualMethod();
152+
}
153+
}
139154
}

test/integration/projects/AccessTest/AccessTestLib/MyClass.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,13 @@ internal struct PublicStructBecomesInternal
155155
public struct PublicStructBecomesInternal
156156
#endif
157157
{ }
158+
159+
// the case of the protected virtual method...
160+
// see RH-37982
161+
162+
public class BaseClassWithProtectedVirtualMethod
163+
{
164+
protected virtual void ProtectedVirtualMethod()
165+
{ }
166+
}
158167
}

0 commit comments

Comments
 (0)