Skip to content
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 @@ -87,6 +87,11 @@ public void AnalyzeInvocation(OperationAnalysisContext context)
internal static void AnalyzeAdd(OperationAnalysisContext context)
{
var operation = (IBinaryOperation)context.Operation;

// Only the built-in string concatenation calls ToString on the operands
if (operation.OperatorKind is not BinaryOperatorKind.Add || operation.OperatorMethod is not null)
return;

if (!operation.Type.IsString())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,25 @@ public struct A{ }
return test.RunAsync();
}

[Fact]
public Task UserDefinedOperatorReturningString()
{
var test = CreateTest();
test.TestCode = """
var a = new Foo();
_ = a - a;
_ = a + a;

sealed class Foo
{
public static string operator -(Foo x, Foo y) => "";
public static string operator +(Foo x, Foo y) => "";
}
""";

return test.RunAsync();
}

[Fact]
public Task SealedRecord_Concat()
{
Expand Down
Loading