Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type infeerence for ICollection #17752

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2443,9 +2443,10 @@ public static IEnumerable<MethodInfo> GetGetterProperty(this Type type, string p
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);
}
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/engine/Api/TypeInference.Tests.ps1
Expand Up @@ -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 {
Expand Down