提交 51d64610 编写于 作者: C Cyrus Najmabadi

Use original defs

上级 878f56bf
......@@ -499,5 +499,21 @@ void Goo(List<int> s)
}
}", parseOptions: s_parseOptions);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseIndexOperator)]
public async Task NotOnConstructedIndexer()
{
await TestMissingInRegularAndScriptAsync(
@"
using System.Collections.Generic;
namespace System { public struct Index { } }
class C
{
void Goo(Dictionary<int, string> s)
{
var v = s[[||]s.Count - 1];
}
}", new TestParameters(parseOptions: s_parseOptions));
}
}
}
......@@ -76,7 +76,11 @@ public static bool IsIntIndexingMethod(IMethodSymbol method)
(method.MethodKind == MethodKind.PropertyGet || method.MethodKind == MethodKind.Ordinary) &&
IsPublicInstance(method) &&
method.Parameters.Length == 1 &&
method.Parameters[0].Type.SpecialType == SpecialType.System_Int32;
// From: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.md#decisions-made-during-implementation
//
// When looking for the pattern members, we look for original definitions, not
// constructed members
method.OriginalDefinition.Parameters[0].Type.SpecialType == SpecialType.System_Int32;
/// <summary>
/// Look for methods like "SomeType MyType.Slice(int start, int length)". Note that the
......@@ -87,8 +91,12 @@ public static bool IsSliceLikeMethod(IMethodSymbol method)
=> method != null &&
IsPublicInstance(method) &&
method.Parameters.Length == 2 &&
IsSliceFirstParameter(method.Parameters[0]) &&
IsSliceSecondParameter(method.Parameters[1]);
// From: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.md#decisions-made-during-implementation
//
// When looking for the pattern members, we look for original definitions, not
// constructed members
IsSliceFirstParameter(method.OriginalDefinition.Parameters[0]) &&
IsSliceSecondParameter(method.OriginalDefinition.Parameters[1]);
private static bool IsSliceFirstParameter(IParameterSymbol parameter)
=> parameter.Type.SpecialType == SpecialType.System_Int32 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册