diff --git a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs index 363ce3536d..3ace7fb3a0 100644 --- a/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs +++ b/src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs @@ -2443,9 +2443,10 @@ namespace System.Management.Automation foreach (var m in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { var name = m.Name; + // Equals without string allocation if (name.Length == propertyName.Length + 4 && name.StartsWith("get_") - && propertyName.IndexOf(name, 4, StringComparison.Ordinal) == 4) + && name.IndexOf(propertyName, 4, StringComparison.Ordinal) == 4) { res.Add(m); } diff --git a/test/powershell/engine/Api/TypeInference.Tests.ps1 b/test/powershell/engine/Api/TypeInference.Tests.ps1 index b5f2f64567..fbcc784570 100644 --- a/test/powershell/engine/Api/TypeInference.Tests.ps1 +++ b/test/powershell/engine/Api/TypeInference.Tests.ps1 @@ -1251,6 +1251,12 @@ Describe "Type inference Tests" -tags "CI" { $res.Count | Should -Be 1 $res.Name | Should -Be 'System.Int32[]' } + + It 'Infers type of index item in an ICollection' -Skip:(!$IsWindows) { + $res = [AstTypeInference]::InferTypeOf( { (Get-Acl -Path C:\).Access[0] }.Ast) + $res.Count | Should -Be 1 + $res.Name | Should -Be 'System.Security.AccessControl.AuthorizationRule' + } } Describe "AstTypeInference tests" -Tags CI {