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 @@ -70,7 +70,7 @@ public static ContainingFunctionData GetContainingFunction(CSharpSyntaxNode? syn
{
BlockSyntax block => accessor.WithBody(block),
ArrowExpressionClauseSyntax expression => accessor.WithExpressionBody(expression),
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
};
return new ContainingFunctionData(accessor, false, SyntaxFactory.ParameterList(), accessor.Body, bodyReplacement);
}
Expand All @@ -83,27 +83,33 @@ public static ContainingFunctionData GetContainingFunction(CSharpSyntaxNode? syn
{
ArrowExpressionClauseSyntax expr => m.WithExpressionBody(expr),
BlockSyntax block => m.WithBody(block),
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
},
ConstructorDeclarationSyntax c => (CSharpSyntaxNode newBody) => newBody switch
{
ArrowExpressionClauseSyntax expr => c.WithExpressionBody(expr),
BlockSyntax block => c.WithBody(block),
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
},
OperatorDeclarationSyntax o => (CSharpSyntaxNode newBody) => newBody switch
{
ArrowExpressionClauseSyntax expr => o.WithExpressionBody(expr),
BlockSyntax block => o.WithBody(block),
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
},
ConversionOperatorDeclarationSyntax c => (CSharpSyntaxNode newBody) => newBody switch
{
ArrowExpressionClauseSyntax expr => c.WithExpressionBody(expr),
BlockSyntax block => c.WithBody(block),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
},
DestructorDeclarationSyntax d => (CSharpSyntaxNode newBody) => newBody switch
{
ArrowExpressionClauseSyntax expr => d.WithExpressionBody(expr),
BlockSyntax block => d.WithBody(block),
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Body syntax type '{newBody.GetType().FullName}' is not supported."),
},
_ => throw new NotSupportedException(),
_ => throw new NotSupportedException($"Method syntax type '{method.GetType().FullName}' is not supported."),
};
return new ContainingFunctionData(method, method.Modifiers.Any(SyntaxKind.AsyncKeyword), method.ParameterList, method.Body, bodyReplacement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ public Task GetTask()
await CSVerify.VerifyAnalyzerAsync(test, expected);
}

[Fact]
public async Task ReturnStatementInConversionOperatorProducesNoDiagnostic()
{
string test = """
readonly struct Wrapper
{
private readonly byte value;

public static implicit operator byte(Wrapper value)
{
return value.value;
}
}
""";

await CSVerify.VerifyAnalyzerAsync(test);
}

[Fact]
public async Task ReportWarningWhenTaskIsReturnedDirectlyFromMethodViaExpressionBody()
{
Expand Down
Loading