diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index eb44031531c..49f60511909 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -935,7 +935,7 @@ internal static bool IsTrue(IList objectArray) // but since we don't want this to recurse indefinitely // we explicitly check the case where it would recurse // and deal with it. - IList firstElement = objectArray[0] as IList; + IList firstElement = PSObject.Base(objectArray[0]) as IList; if (firstElement == null) { diff --git a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 index f6476e3c023..04ebb0b9829 100644 --- a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 +++ b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 @@ -25,4 +25,9 @@ $ObjArray = [System.Management.Automation.LanguagePrimitives]::ConvertTo($col, [object[]]) $ObjArray.Length | Should Be $col.Count } + + It "Casting recursive array to bool should not cause crash" { + $a[0] = $a = [PSObject](,1) + [System.Management.Automation.LanguagePrimitives]::IsTrue($a) | Should Be $true + } }