Skip to content

Commit 841b220

Browse files
Dummy compilation unit for when errors happen at the top level
1 parent 6ab2326 commit 841b220

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

CodeConverter/CSharp/CommentConvertingVisitorWrapper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ internal class CommentConvertingVisitorWrapper
1818
{
1919
private readonly VBasic.VisualBasicSyntaxVisitor<Task<CS.CSharpSyntaxNode>> _wrappedVisitor;
2020
private readonly SyntaxTree _syntaxTree;
21-
private static readonly CSSyntax.StatementSyntax _dummyStatement = CS.SyntaxFactory.EmptyStatement();
2221
private static readonly CSSyntax.LiteralExpressionSyntax _dummyLiteral = ValidSyntaxFactory.DefaultExpression;
22+
private static readonly CSSyntax.StatementSyntax _dummyStatement = CS.SyntaxFactory.EmptyStatement();
23+
private static readonly CSSyntax.CompilationUnitSyntax _dummyCompilationUnit = CS.SyntaxFactory.CompilationUnit();
2324

2425
public CommentConvertingVisitorWrapper(VisualBasicSyntaxVisitor<Task<CSharpSyntaxNode>> wrappedVisitor, SyntaxTree syntaxTree)
2526
{
@@ -50,9 +51,11 @@ private async Task<T> ConvertHandledAsync<T>(VisualBasicSyntaxNode vbNode, Sourc
5051
: sourceTriviaMap == SourceTriviaMapKind.SubNodesOnly
5152
? converted
5253
: WithSourceMapping(vbNode, converted);
54+
} catch (Exception e) when (_dummyLiteral is T dummy) {
55+
return dummy.WithCsTrailingErrorComment(vbNode, e);
5356
} catch (Exception e) when (_dummyStatement is T dummy) {
5457
return dummy.WithCsTrailingErrorComment(vbNode, e);
55-
} catch (Exception e) when (_dummyLiteral is T dummy) {
58+
} catch (Exception e) when (_dummyCompilationUnit is T dummy) {
5659
return dummy.WithCsTrailingErrorComment(vbNode, e);
5760
} catch (Exception e) when (!(e is ExceptionWithNodeInformation)) {
5861
throw e.WithNodeInformation(vbNode);

0 commit comments

Comments
 (0)