Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a2ea3dd
Add design for converting On Error and Resume statements
claude Nov 17, 2026
d428cc6
On Error design: exact form for re-entrant handlers, widen Err detection
claude Nov 17, 2026
e7be0f2
Move On Error conversion out of LambdaConverter
claude Nov 17, 2026
990559b
Extract the implicit method exit from VisitExitStatement
claude Nov 17, 2026
7e1aff5
Add the On Error model, shape selection and Err usage analysis
claude Nov 17, 2026
3022b70
Convert structured On Error GoTo handlers to try/catch
claude Nov 17, 2026
91c8c4f
Update the On Error README to what is implemented
claude Nov 17, 2026
fb3e206
Drop a redundant check from StructuredPlanner
claude Nov 17, 2026
03db4de
Test more On Error shapes and re-entry guard conditions
claude Nov 17, 2026
f719893
Extract DeclarationSplitter from LocalHoisting
claude Nov 17, 2026
c269205
Let a decorator change how every statement is converted
claude Nov 17, 2026
76b0202
Share default initializers and let a catch have a filter
claude Nov 17, 2026
b558a30
Convert On Error Resume Next with a guard per resume point
claude Nov 17, 2026
62d0085
Test the dynamic On Error Resume Next shape
claude Nov 17, 2026
617e475
Convert On Error GoTo handlers that resume into the covered statements
claude Nov 17, 2026
18f8fb2
Cover non-constant Select cases and lambdas in handlers; drop an unus…
claude Nov 17, 2026
40446c9
Return from a structured On Error function whose handler falls off th…
claude Nov 17, 2026
0e04a74
Keep a guarded Dim's value across loop iterations under Resume Next
claude Nov 17, 2026
5a293b4
Fall back instead of splitting a local whose type can't be written
claude Nov 17, 2026
27a3a23
Enter the case whose Case expression fails under Resume Next
claude Nov 17, 2026
b33796e
Document that a retry-only handler keeps the fallback
claude Nov 17, 2026
39da3f3
Don't add an exit after a handler function whose every branch leaves
claude Nov 17, 2026
27883fb
Drop the trailing return from a void handler function
claude Nov 17, 2026
8cc3962
Test returns in lambdas in handlers and the planners' rejections
claude Nov 17, 2026
e91dd71
Keep the fallback for local functions in struct instance members
claude Nov 18, 2026
d351635
Don't generate a label that clashes with a label of the method
claude Nov 18, 2026
f0fa1f7
Only look labels up when generating a label name
claude Nov 18, 2026
17e9eae
Keep the fallback when hoisting a guarded Dim out of a loop would cla…
claude Nov 18, 2026
ae46d83
Convert a handler that leaves to a label after itself as a structured…
claude Nov 18, 2026
480d552
Convert a lone On Error GoTo 0 to a clear of Err
claude Nov 18, 2026
efefc8a
Treat creating a lambda as unable to fail under Resume Next
claude Nov 18, 2026
856a0de
Don't emit statements after the handler function has left
claude Nov 18, 2026
fc5147a
Don't clear Err after code that always leaves
claude Nov 18, 2026
18c0b40
Document that VB loops forever when a For Step expression fails
claude Nov 18, 2026
d3835eb
Test the reachability, throw and planner branches the conversion test…
claude Nov 18, 2026
92ecd88
Add a return after a handler's tail that can end reachably
claude Nov 18, 2026
c1c64ac
Don't leave a retry loop unprotected when the handler resumes to a label
claude Nov 18, 2026
ad88613
Skip the empty segment of the segmented structured form
claude Nov 18, 2026
adf3037
Treat unchecked integer arithmetic on locals as unable to fail
claude Nov 18, 2026
d891097
Convert On Error GoTo 0 in a structured handler as a clear of Err
claude Nov 18, 2026
ca3409d
Document two fallbacks in the On Error README and pin the first
claude Nov 18, 2026
a163e84
Don't leave a one-shot retry's first pass unprotected
claude Nov 18, 2026
6d42f7d
Count conditions in resumed-to code only for a retry into the covered…
claude Nov 18, 2026
6ff5b34
Don't let a handler's On Error GoTo 0 make a label after the handler …
claude Nov 18, 2026
cc91f6d
Pin that integer arithmetic stays guarded when its types differ or it…
claude Nov 18, 2026
d06d6aa
Keep a handler's comments in the catch when its first statement conve…
claude Nov 18, 2026
4523c4e
Only let an On Error GoTo 0 in a handler force the fallback when a ju…
claude Nov 18, 2026
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
5 changes: 4 additions & 1 deletion CodeConverter/CSharp/CommonConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using ICSharpCode.CodeConverter.Util.FromRoslyn;
using ICSharpCode.CodeConverter.CSharp.OnError;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editing;
Expand Down Expand Up @@ -40,8 +41,9 @@ internal class CommonConversions
public CommonConversions(Document document, SemanticModel semanticModel,
TypeConversionAnalyzer typeConversionAnalyzer, SyntaxGenerator csSyntaxGenerator,
Compilation compilation,
CSharpCompilation csCompilation, ITypeContext typeContext, VisualBasicEqualityComparison visualBasicEqualityComparison)
CSharpCompilation csCompilation, ITypeContext typeContext, VisualBasicEqualityComparison visualBasicEqualityComparison, ErrUsage errUsage)
{
ErrUsage = errUsage;
TypeConversionAnalyzer = typeConversionAnalyzer;
Document = document;
SemanticModel = semanticModel;
Expand All @@ -55,6 +57,7 @@ public CommonConversions(Document document, SemanticModel semanticModel,
}

public KnownNamedTypes KnownTypes { get; }
public ErrUsage ErrUsage { get; }

public record VariablePair(CSSyntax.VariableDeclaratorSyntax CsVar, VBSyntax.ModifiedIdentifierSyntax VbVar);
public record VariablesDeclaration(CSSyntax.VariableDeclarationSyntax Decl, ITypeSymbol Type, List<VariablePair> Variables);
Expand Down
7 changes: 4 additions & 3 deletions CodeConverter/CSharp/DeclarationNodeVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Immutable;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using static Microsoft.CodeAnalysis.VisualBasic.VisualBasicExtensions;
using ICSharpCode.CodeConverter.Util.FromRoslyn;
using ICSharpCode.CodeConverter.CSharp.OnError;
using ISymbolExtensions = ICSharpCode.CodeConverter.Util.ISymbolExtensions;

namespace ICSharpCode.CodeConverter.CSharp;
Expand Down Expand Up @@ -42,7 +43,7 @@ internal class DeclarationNodeVisitor : VBasic.VisualBasicSyntaxVisitor<Task<CSh
internal PerScopeState AdditionalLocals => _typeContext.PerScopeState;

public DeclarationNodeVisitor(Document document, Compilation compilation, SemanticModel semanticModel,
CSharpCompilation csCompilation, SyntaxGenerator csSyntaxGenerator, ILookup<ITypeSymbol, ITypeSymbol> typeToInheritors)
CSharpCompilation csCompilation, SyntaxGenerator csSyntaxGenerator, ILookup<ITypeSymbol, ITypeSymbol> typeToInheritors, ErrUsage errUsage)
{
_vbCompilation = compilation;
_csSyntaxGenerator = csSyntaxGenerator;
Expand All @@ -54,7 +55,7 @@ public DeclarationNodeVisitor(Document document, Compilation compilation, Semant
var expressionEvaluator = new ExpressionEvaluator(semanticModel, _visualBasicEqualityComparison);
var nullableExpressionsConverter = new VisualBasicNullableExpressionsConverter(_semanticModel);
var typeConversionAnalyzer = new TypeConversionAnalyzer(semanticModel, csCompilation, _extraUsingDirectives, _csSyntaxGenerator, expressionEvaluator, nullableExpressionsConverter);
CommonConversions = new CommonConversions(document, semanticModel, typeConversionAnalyzer, csSyntaxGenerator, compilation, csCompilation, _typeContext, _visualBasicEqualityComparison);
CommonConversions = new CommonConversions(document, semanticModel, typeConversionAnalyzer, csSyntaxGenerator, compilation, csCompilation, _typeContext, _visualBasicEqualityComparison, errUsage);
var expressionNodeVisitor = new ExpressionNodeVisitor(semanticModel, _visualBasicEqualityComparison, _typeContext, CommonConversions, _extraUsingDirectives, _xmlImportContext, nullableExpressionsConverter);
_accessorDeclarationNodeConverter = new AccessorDeclarationNodeConverter(semanticModel, CommonConversions, TriviaConvertingDeclarationVisitor, _additionalDeclarations, expressionNodeVisitor.ConvertMethodBodyStatementsAsync);
_triviaConvertingExpressionVisitor = CommonConversions.TriviaConvertingExpressionVisitor;
Expand Down
44 changes: 3 additions & 41 deletions CodeConverter/CSharp/LambdaConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;
using ICSharpCode.CodeConverter.CSharp.OnError;

namespace ICSharpCode.CodeConverter.CSharp;

Expand Down Expand Up @@ -200,47 +201,8 @@ public async Task<IReadOnlyCollection<StatementSyntax>> ConvertMethodBodyStateme
{

var innerMethodBodyVisitor = await MethodBodyExecutableStatementVisitor.CreateAsync(node, _semanticModel, CommonConversions.TriviaConvertingExpressionVisitor, CommonConversions, CommonConversions.VisualBasicEqualityComparison, _withBlockLhs, _extraUsingDirectives, _typeContext, isIterator, csReturnVariable);
return await GetWithConvertedGotosOrNull(statements) ?? await ConvertStatements(statements);

async Task<List<StatementSyntax>> ConvertStatements(IEnumerable<VBSyntax.StatementSyntax> readOnlyCollection)
{
return (await readOnlyCollection.SelectManyAsync(async s => (IEnumerable<StatementSyntax>)await s.Accept(innerMethodBodyVisitor.CommentConvertingVisitor))).ToList();
}

async Task<IReadOnlyCollection<StatementSyntax>> GetWithConvertedGotosOrNull(IReadOnlyCollection<Microsoft.CodeAnalysis.VisualBasic.Syntax.StatementSyntax> statements)
{
var onlyIdentifierLabel = statements.OnlyOrDefault(s => s.IsKind(VBasic.SyntaxKind.LabelStatement));
var onlyOnErrorGotoStatement = statements.OnlyOrDefault(s => s.IsKind(VBasic.SyntaxKind.OnErrorGoToLabelStatement));

// See https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/on-error-statement
if (onlyIdentifierLabel != null && onlyOnErrorGotoStatement != null) {
var statementsList = statements.ToList();
var onlyIdentifierLabelIndex = statementsList.IndexOf(onlyIdentifierLabel);
var onlyOnErrorGotoStatementIndex = statementsList.IndexOf(onlyOnErrorGotoStatement);

// Even this very simple case can generate compile errors if the error handling uses statements declared in the scope of the try block
// For now, the user will have to fix these manually, in future it'd be possible to hoist any used declarations out of the try block
if (onlyOnErrorGotoStatementIndex < onlyIdentifierLabelIndex) {
var beforeStatements = await ConvertStatements(statements.Take(onlyOnErrorGotoStatementIndex));
var tryBlockStatements = await ConvertStatements(statements.Take(onlyIdentifierLabelIndex).Skip(onlyOnErrorGotoStatementIndex + 1));
var tryBlock = SyntaxFactory.Block(tryBlockStatements);
var afterStatements = await ConvertStatements(statements.Skip(onlyIdentifierLabelIndex + 1));

var catchClauseSyntax = SyntaxFactory.CatchClause();

// Default to putting the statements after the catch block in case logic falls through, but if the last statement is a return, put them inside the catch block for neatness.
if (tryBlockStatements.LastOrDefault().IsKind(SyntaxKind.ReturnStatement)) {
catchClauseSyntax = catchClauseSyntax.WithBlock(SyntaxFactory.Block(afterStatements));
afterStatements = new List<StatementSyntax>();
}

var tryStatement = SyntaxFactory.TryStatement(SyntaxFactory.SingletonList(catchClauseSyntax)).WithBlock(tryBlock);
return beforeStatements.Append(tryStatement).Concat(afterStatements).ToList();
}
}

return null;
}
var onErrorContext = new OnErrorConversionContext(node, _semanticModel, CommonConversions, innerMethodBodyVisitor, _extraUsingDirectives);
return await OnErrorMethodBodyConverter.ConvertOrNullAsync(onErrorContext, statements) ?? await onErrorContext.ConvertAsync(statements);
}

/// <summary>
Expand Down
96 changes: 73 additions & 23 deletions CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Text;
using ICSharpCode.CodeConverter.Util.FromRoslyn;
using ICSharpCode.CodeConverter.VB;
using ICSharpCode.CodeConverter.CSharp.OnError;
using ComparisonKind = ICSharpCode.CodeConverter.CSharp.VisualBasicEqualityComparison.ComparisonKind;

namespace ICSharpCode.CodeConverter.CSharp;
Expand All @@ -28,14 +29,29 @@ internal class MethodBodyExecutableStatementVisitor : VBasic.VisualBasicSyntaxVi
private readonly HashSet<string> _generatedNames = new();
private readonly HashSet<ILocalSymbol> _localsToInlineInLoop;
private readonly PerScopeState _perScopeState;
private VBasic.VisualBasicSyntaxVisitor<Task<SyntaxList<StatementSyntax>>> _statementVisitor;

public bool IsIterator { get; set; }
public IdentifierNameSyntax ReturnVariable { get; set; }
public bool HasReturnVariable => ReturnVariable != null;
public VBasic.VisualBasicSyntaxVisitor<Task<SyntaxList<StatementSyntax>>> CommentConvertingVisitor { get; }
/// <summary>How nested statements are converted: every statement is visited through this, whatever its depth.</summary>
public VBasic.VisualBasicSyntaxVisitor<Task<SyntaxList<StatementSyntax>>> CommentConvertingVisitor { get; private set; }

/// <summary>Set by the On Error conversion for the shape it emits. Until then, On Error and Resume statements can't be converted.</summary>
public IOnErrorStatementConverter OnErrorStatementConverter { get; set; }

private CommonConversions CommonConversions { get; }

/// <summary>
/// Lets another class change the conversion of each statement at every nesting depth, without this visitor knowing why.
/// The decorator sits inside the comment conversion, so comments attach to whatever it returns for the statement.
/// </summary>
public void DecorateStatementVisitor(Func<VBasic.VisualBasicSyntaxVisitor<Task<SyntaxList<StatementSyntax>>>, VBasic.VisualBasicSyntaxVisitor<Task<SyntaxList<StatementSyntax>>>> decorate)
{
_statementVisitor = decorate(_statementVisitor);
CommentConvertingVisitor = new CommentConvertingMethodBodyVisitor(_statementVisitor);
}

public static async Task<MethodBodyExecutableStatementVisitor> CreateAsync(VisualBasicSyntaxNode node, SemanticModel semanticModel,
CommentConvertingVisitorWrapper triviaConvertingExpressionVisitor, CommonConversions commonConversions, VisualBasicEqualityComparison visualBasicEqualityComparison,
Stack<ExpressionSyntax> withBlockLhs, HashSet<string> extraUsingDirectives,
Expand Down Expand Up @@ -64,8 +80,8 @@ private MethodBodyExecutableStatementVisitor(VisualBasicSyntaxNode methodNode, S
_extraUsingDirectives = extraUsingDirectives;
_handledEventsAnalysis = typeContext.HandledEventsAnalysis;
_perScopeState = typeContext.PerScopeState;
var byRefParameterVisitor = new PerScopeStateVisitorDecorator(this, _perScopeState, semanticModel, _generatedNames);
CommentConvertingVisitor = new CommentConvertingMethodBodyVisitor(byRefParameterVisitor);
_statementVisitor = new PerScopeStateVisitorDecorator(this, _perScopeState, semanticModel, _generatedNames);
CommentConvertingVisitor = new CommentConvertingMethodBodyVisitor(_statementVisitor);
_localsToInlineInLoop = localsToInlineInLoop;
}

Expand All @@ -75,6 +91,15 @@ public override async Task<SyntaxList<StatementSyntax>> DefaultVisit(SyntaxNode
.WithNodeInformation(node);
}

public override Task<SyntaxList<StatementSyntax>> VisitOnErrorGoToStatement(VBSyntax.OnErrorGoToStatementSyntax node) =>
OnErrorStatementConverter is { } converter ? Task.FromResult(converter.ConvertOnError(node)) : DefaultVisit(node);

public override Task<SyntaxList<StatementSyntax>> VisitOnErrorResumeNextStatement(VBSyntax.OnErrorResumeNextStatementSyntax node) =>
OnErrorStatementConverter is { } converter ? Task.FromResult(converter.ConvertOnError(node)) : DefaultVisit(node);

public override Task<SyntaxList<StatementSyntax>> VisitResumeStatement(VBSyntax.ResumeStatementSyntax node) =>
OnErrorStatementConverter is { } converter ? Task.FromResult(converter.ConvertResume(node)) : DefaultVisit(node);

public override async Task<SyntaxList<StatementSyntax>> VisitStopOrEndStatement(VBSyntax.StopOrEndStatementSyntax node)
{
return SingleStatement(SyntaxFactory.ParseStatement(ConvertStopOrEndToCSharpStatementText(node)));
Expand Down Expand Up @@ -148,6 +173,18 @@ public override async Task<SyntaxList<StatementSyntax>> VisitLocalDeclarationSta
return SyntaxFactory.List(declarations);
}

/// <summary>
/// Declares a local that was converted in a loop body before the outermost loop instead, as a VB local keeps its value from one iteration to the next.
/// Call it after the declaration has been converted, as the scope of the declaration itself has then been left.
/// </summary>
/// <returns>False when the declaration isn't in a loop, so the caller declares it where it is.</returns>
public bool TryHoistOutOfLoop(string name, TypeSyntax type)
{
if (!_perScopeState.IsWithinLoopBody()) return false;
_perScopeState.Hoist(new HoistedDefaultInitializedLoopVariable(name, SyntaxFactory.DefaultExpression(type), type, _perScopeState.IsWithinNestedLoopBody()));
return true;
}

private IEnumerable<VariableDeclarationSyntax> HoistVariablesBeforeLoopWhenNeeded(IEnumerable<CommonConversions.VariablesDeclaration> variablesDeclarations)
{
foreach (var variablesDecl in variablesDeclarations) {
Expand Down Expand Up @@ -525,29 +562,37 @@ public override async Task<SyntaxList<StatementSyntax>> VisitExitStatement(VBSyn
return SingleStatement(SyntaxFactory.ReturnStatement());
case VBasic.SyntaxKind.FunctionKeyword:
case VBasic.SyntaxKind.PropertyKeyword when node.GetAncestor<VBSyntax.AccessorBlockSyntax>()?.IsKind(VBasic.SyntaxKind.GetAccessorBlock) == true:
VBasic.VisualBasicSyntaxNode typeContainer = node.GetAncestor<VBSyntax.LambdaExpressionSyntax>()
?? (VBasic.VisualBasicSyntaxNode)node.GetAncestor<VBSyntax.MethodBlockSyntax>()
?? node.GetAncestor<VBSyntax.AccessorBlockSyntax>();
var enclosingMethodInfo = typeContainer switch {
VBSyntax.LambdaExpressionSyntax e => _semanticModel.GetSymbolInfo(e).Symbol,
VBSyntax.MethodBlockSyntax e => _semanticModel.GetDeclaredSymbol(e.SubOrFunctionStatement),
VBSyntax.AccessorBlockSyntax e => _semanticModel.GetDeclaredSymbol(e.AccessorStatement),
_ => null
} as IMethodSymbol;

if (IsIterator) return SingleStatement(SyntaxFactory.YieldStatement(SyntaxKind.YieldBreakStatement));

if (!enclosingMethodInfo.ReturnsVoidOrAsyncTask()) {
ExpressionSyntax expr = HasReturnVariable ? ReturnVariable : SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression);
return SingleStatement(SyntaxFactory.ReturnStatement(expr));
}

return SingleStatement(SyntaxFactory.ReturnStatement());
return SingleStatement(CreateMethodExitStatement(node));
default:
return SyntaxFactory.List(_perScopeState.ConvertExit(vbBlockKeywordKind));
}
}

/// <summary>
/// What leaving the method containing <paramref name="node"/> without a <c>Return</c> statement does: for a function, return its return variable or the default value.
/// </summary>
public StatementSyntax CreateMethodExitStatement(VBasic.VisualBasicSyntaxNode node)
{
VBasic.VisualBasicSyntaxNode typeContainer = node.GetAncestor<VBSyntax.LambdaExpressionSyntax>()
?? (VBasic.VisualBasicSyntaxNode)node.GetAncestor<VBSyntax.MethodBlockSyntax>()
?? node.GetAncestor<VBSyntax.AccessorBlockSyntax>();
var enclosingMethodInfo = typeContainer switch {
VBSyntax.LambdaExpressionSyntax e => _semanticModel.GetSymbolInfo(e).Symbol,
VBSyntax.MethodBlockSyntax e => _semanticModel.GetDeclaredSymbol(e.SubOrFunctionStatement),
VBSyntax.AccessorBlockSyntax e => _semanticModel.GetDeclaredSymbol(e.AccessorStatement),
_ => null
} as IMethodSymbol;

if (IsIterator) return SyntaxFactory.YieldStatement(SyntaxKind.YieldBreakStatement);

if (!enclosingMethodInfo.ReturnsVoidOrAsyncTask()) {
ExpressionSyntax expr = HasReturnVariable ? ReturnVariable : SyntaxFactory.LiteralExpression(SyntaxKind.DefaultLiteralExpression);
return SyntaxFactory.ReturnStatement(expr);
}

return SyntaxFactory.ReturnStatement();
}

public override async Task<SyntaxList<StatementSyntax>> VisitRaiseEventStatement(VBSyntax.RaiseEventStatementSyntax node)
{
var argumentListSyntax = await node.ArgumentList.AcceptAsync<ArgumentListSyntax>(_expressionVisitor) ?? SyntaxFactory.ArgumentList();
Expand Down Expand Up @@ -1098,11 +1143,16 @@ public override async Task<SyntaxList<StatementSyntax>> VisitWithBlock(VBSyntax.
}
}

private string GetUniqueVariableNameInScope(VBasic.VisualBasicSyntaxNode node, string variableNameBase)
public string GetUniqueVariableNameInScope(VBasic.VisualBasicSyntaxNode node, string variableNameBase)
{
return NameGenerator.CS.GetUniqueVariableNameInScope(_semanticModel, _generatedNames, node, variableNameBase);
}

public string GetUniqueLabelNameInScope(VBasic.VisualBasicSyntaxNode node, string labelNameBase)
{
return NameGenerator.CS.GetUniqueLabelNameInScope(_semanticModel, _generatedNames, node, labelNameBase);
}

public override async Task<SyntaxList<StatementSyntax>> VisitTryBlock(VBSyntax.TryBlockSyntax node)
{
var block = SyntaxFactory.Block(await ConvertStatementsAsync(node.Statements));
Expand Down Expand Up @@ -1238,4 +1288,4 @@ private static SyntaxList<StatementSyntax> SingleStatement(CSharpSyntaxNode node
? statement
: SyntaxFactory.ExpressionStatement((ExpressionSyntax)node));
}
}
}
18 changes: 18 additions & 0 deletions CodeConverter/CSharp/OnError/ActiveHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ICSharpCode.CodeConverter.CSharp.OnError;

internal enum ActiveHandlerKind
{
None,
ResumeNext,
Label
}

/// <summary>
/// What VB does with an error raised by a statement: the value of the lowered method's "active handler" local, set by the last <c>On Error</c> statement executed.
/// </summary>
internal sealed record ActiveHandler(ActiveHandlerKind Kind, string Label = null)
{
public static ActiveHandler None { get; } = new(ActiveHandlerKind.None);
public static ActiveHandler ResumeNext { get; } = new(ActiveHandlerKind.ResumeNext);
public static ActiveHandler ForLabel(string label) => new(ActiveHandlerKind.Label, LabelName.Normalize(label));
}
Loading
Loading