@@ -219,7 +219,69 @@ Describe 'Classes methods with inheritance' -Tags "CI" {
219219 [baz ]::new().foo() | Should - Be 200600
220220 }
221221
222- It ' allows base class method call and doesn'' t fall into recursion' {
222+ It ' allows base .NET class method call and doesn'' t fall into recursion' {
223+ Add-Type - TypeDefinition @'
224+ public class BaseMembersTestClass
225+ {
226+ public virtual int PublicMethod()
227+ {
228+ return 1001;
229+ }
230+
231+ protected virtual int FamilyMethod()
232+ {
233+ return 2002;
234+ }
235+
236+ protected internal virtual int FamilyOrAssemblyMethod()
237+ {
238+ return 3003;
239+ }
240+ }
241+ '@
242+ $derived = Invoke-Expression @'
243+ class BaseCallTestClass : BaseMembersTestClass
244+ {
245+ hidden [int] $publicMethodCallCounter
246+ [int] PublicMethod()
247+ {
248+ if ($this.publicMethodCallCounter++ -gt 0)
249+ {
250+ throw "Recursion happens"
251+ }
252+ return 3 * ([BaseMembersTestClass]$this).PublicMethod()
253+ }
254+
255+ hidden [int] $familyMethodCallCounter
256+ [int] FamilyMethod()
257+ {
258+ if ($this.familyMethodCallCounter++ -gt 0)
259+ {
260+ throw "Recursion happens"
261+ }
262+ return 3 * ([BaseMembersTestClass]$this).FamilyMethod()
263+ }
264+
265+ hidden [int] $familyOrAssemblyMethodCallCounter
266+ [int] FamilyOrAssemblyMethod()
267+ {
268+ if ($this.familyOrAssemblyMethodCallCounter++ -gt 0)
269+ {
270+ throw "Recursion happens"
271+ }
272+ return 3 * ([BaseMembersTestClass]$this).FamilyOrAssemblyMethod()
273+ }
274+ }
275+
276+ [BaseCallTestClass]::new()
277+ '@
278+
279+ $derived.PublicMethod () | Should - Be 3003
280+ $derived.FamilyMethod () | Should - Be 6006
281+ $derived.FamilyOrAssemblyMethod () | Should - Be 9009
282+ }
283+
284+ It ' allows base PowerShell class method call and doesn'' t fall into recursion' {
223285 class bar
224286 {
225287 [int ]foo() {return 1001 }
0 commit comments