Skip to content

Commit d384eaa

Browse files
The method shouldn't say non-methods/nulls can have method bodies, knowing what to do in the edge case is the caller's responsibility
1 parent b3ad175 commit d384eaa

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

CodeConverter/CSharp/DeclarationNodeVisitor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ public override async Task<CSharpSyntaxNode> VisitMethodBlock(VBSyntax.MethodBlo
655655
var methodBlock = await node.SubOrFunctionStatement.AcceptAsync<BaseMethodDeclarationSyntax>(TriviaConvertingDeclarationVisitor, SourceTriviaMapKind.SubNodesOnly);
656656

657657
var declaredSymbol = ModelExtensions.GetDeclaredSymbol(_semanticModel, node);
658-
if (!declaredSymbol.CanHaveMethodBody()) {
658+
if (declaredSymbol?.CanHaveMethodBody() == false) {
659659
return methodBlock;
660660
}
661661
var csReturnVariableOrNull = CommonConversions.GetRetVariableNameOrNull(node);
@@ -786,7 +786,8 @@ public override async Task<CSharpSyntaxNode> VisitMethodStatement(VBSyntax.Metho
786786
null
787787
);
788788

789-
return hasBody && declaredSymbol.CanHaveMethodBody() ? decl : decl.WithSemicolonToken(SemicolonToken);
789+
bool canHaveMethodBody = declaredSymbol?.CanHaveMethodBody() != false;
790+
return hasBody && canHaveMethodBody ? decl : decl.WithSemicolonToken(SemicolonToken);
790791
}
791792

792793
public override async Task<CSharpSyntaxNode> VisitEventBlock(VBSyntax.EventBlockSyntax node)

CodeConverter/Util/ISymbolExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static bool IsPartialMethodImplementation(this ISymbol declaredSymbol)
7575

7676
public static bool CanHaveMethodBody(this ISymbol declaredSymbol)
7777
{
78-
return !(declaredSymbol is IMethodSymbol ms) || (!ms.IsPartialDefinition && (ms.PartialImplementationPart == null && !ms.IsExtern));
78+
return declaredSymbol is IMethodSymbol ms && (!ms.IsPartialDefinition && (ms.PartialImplementationPart == null && !ms.IsExtern));
7979
}
8080

8181
public static bool IsPartialMethodDefinition(this ISymbol declaredSymbol)

0 commit comments

Comments
 (0)