提交 d3fcb5f7 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #21592 from CyrusNajmabadi/usePatternMatchingUserOperator

Don't offer to use pattern matching if a user defined operator was involved.
...@@ -743,6 +743,26 @@ void M(object o) ...@@ -743,6 +743,26 @@ void M(object o)
{ {
} }
} }
}");
}
[WorkItem(21551, "https://github.com/dotnet/roslyn/issues/21551")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTypeCheck)]
public async Task TestOverloadedUserOperator()
{
await TestMissingAsync(
@"class C
{
public static void Main()
{
object o = new C();
[|var|] c = o as C;
if (c != null)
System.Console.WriteLine();
}
public static bool operator ==(C c1, C c2) => false;
public static bool operator !=(C c1, C c2) => false;
}"); }");
} }
} }
......
...@@ -95,6 +95,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext) ...@@ -95,6 +95,11 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
} }
var semanticModel = syntaxContext.SemanticModel; var semanticModel = syntaxContext.SemanticModel;
if (semanticModel.GetSymbolInfo(comparison).GetAnySymbol().IsUserDefinedOperator())
{
return;
}
var typeNode = ((BinaryExpressionSyntax)asExpression).Right; var typeNode = ((BinaryExpressionSyntax)asExpression).Right;
var asType = semanticModel.GetTypeInfo(typeNode, cancellationToken).Type; var asType = semanticModel.GetTypeInfo(typeNode, cancellationToken).Type;
if (asType.IsNullable()) if (asType.IsNullable())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册