Fix type inference for ICollection (#17752)

This commit is contained in:
MartinGC94
2022-07-25 11:15:19 -07:00
committed by GitHub
parent 89cc6d1297
commit 5ccbb97ae3
2 changed files with 8 additions and 1 deletions
@@ -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);
}
@@ -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 {