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

Support checked operators in explicit interface implementation completion #60715

Merged
merged 1 commit into from
Apr 14, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -888,5 +888,110 @@ void I.M(int x)
// TODO: Consider adding the default value too.
await VerifyProviderCommitAsync(markup, "M(int x)", expected, '\t');
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(60215, "https://github.com/dotnet/roslyn/issues/60215")]
public async Task TestStaticAbstractCheckedUnaryOperator()
{
var markup = @"
interface I1<T> where T : I1<T>
{
abstract static T operator checked -(T x);

abstract static T operator -(T x);
}

class C : I1<C>
{
static C I1<C>.$$
}
";

var expected = @"
interface I1<T> where T : I1<T>
{
abstract static T operator checked -(T x);

abstract static T operator -(T x);
}

class C : I1<C>
{
static C I1<C>.operator checked -(C x)
}
";

await VerifyProviderCommitAsync(markup, "operator checked -(C x)", expected, '\t');
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(60215, "https://github.com/dotnet/roslyn/issues/60215")]
public async Task TestStaticAbstractCheckedBinaryOperator()
{
var markup = @"
interface I1<T> where T : I1<T>
{
abstract static T operator checked +(T x, T y);

abstract static T operator +(T x, T y);
}

class C : I1<C>
{
static C I1<C>.$$
}
";

var expected = @"
interface I1<T> where T : I1<T>
{
abstract static T operator checked +(T x, T y);

abstract static T operator +(T x, T y);
}

class C : I1<C>
{
static C I1<C>.operator checked +(C x, C y)
}
";

await VerifyProviderCommitAsync(markup, "operator checked +(C x, C y)", expected, '\t');
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
[WorkItem(60215, "https://github.com/dotnet/roslyn/issues/60215")]
public async Task TestStaticAbstractCheckedCastOperator()
{
var markup = @"
interface I1<T> where T : I1<T>
{
abstract static explicit operator checked string(T x);
abstract static explicit operator string(T x);
}


class C3 : I1<C3>
{
static C3 I1<C3>.$$
}
";

var expected = @"
interface I1<T> where T : I1<T>
{
abstract static explicit operator checked string(T x);
abstract static explicit operator string(T x);
}


class C3 : I1<C3>
{
static C3 I1<C3>.operator checked string(C3 x)
}
";

await VerifyProviderCommitAsync(markup, "operator checked string(C3 x)", expected, '\t');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private static string ToDisplayString(IMethodSymbol symbol)
break;
case MethodKind.UserDefinedOperator:
case MethodKind.BuiltinOperator:
builder.Append("operator ");
AppendOperatorKeywords(symbol, builder);
builder.Append(SyntaxFacts.GetText(SyntaxFacts.GetOperatorKind(symbol.MetadataName)));
break;
case MethodKind.Conversion:
builder.Append("operator ");
AppendOperatorKeywords(symbol, builder);
AddType(symbol.ReturnType, builder);
break;
}
Expand All @@ -73,6 +73,15 @@ private static string ToDisplayString(IMethodSymbol symbol)
AddParameters(symbol.Parameters, builder);
builder.Append(')');
return builder.ToString();

static void AppendOperatorKeywords(IMethodSymbol symbol, StringBuilder builder)
{
builder.Append("operator ");
if (SyntaxFacts.IsCheckedOperator(symbol.MetadataName))
{
builder.Append("checked ");
}
}
}

private static void AddParameters(ImmutableArray<IParameterSymbol> parameters, StringBuilder builder)
Expand Down