Skip to content

Commit 9e517c4

Browse files
authored
Merge pull request #25 from CoderNate/empty-catch
Handle empty catch statements
2 parents 5ae9aec + 1d521cb commit 9e517c4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/cs2fs/cs2fs.fs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,17 +555,26 @@ let rec convertNode tryImplicitConv (model: SemanticModel) (node: SyntaxNode) :
555555
ExprInfixApp(node, e1, ValId "?.", e2)
556556
| TryStatementSyntax (_, body, catches, finallyBody) ->
557557
let getMatch = function
558-
| CatchClauseSyntax (_, CatchDeclarationSyntax(_,t,tok,_), filter, block) as catchNode ->
558+
| CatchClauseSyntax (_, catchDecl, filter, block) as catchNode ->
559559
let exprFilter = match filter with |CatchFilterClauseSyntax(_,_,x,_) -> Some x |_ -> None
560-
let ident = let x = tok.ValueText in if String.isNullOrEmpty x then PatWildcard catchNode else mkPatBind catchNode x
561-
let typeCheckPat = function
562-
| PatWithType(ctx, t, PatWildcard ctx1) -> PatWithType(ctx, t, PatWildcard ctx1)
563-
| PatWithType(ctx, t, PatBind (ctx1, x)) -> PatBindAs(ctx, x, PatWithType(ctx1, t, PatWildcard ctx1))
564-
| x -> failwithf "Unexpected case %A" x
560+
let basePat =
561+
match catchDecl with
562+
| CatchDeclarationSyntax(_,t,tok,_) ->
563+
let ident =
564+
let x = tok.ValueText in
565+
if String.isNullOrEmpty x then PatWildcard catchNode
566+
else mkPatBind catchNode x
567+
let typeCheckPat = function
568+
| PatWithType(ctx, t, PatWildcard ctx1) -> PatWithType(ctx, t, PatWildcard ctx1)
569+
| PatWithType(ctx, t, PatBind (ctx1, x)) -> PatBindAs(ctx, x, PatWithType(ctx1, t, PatWildcard ctx1))
570+
| x -> failwithf "Unexpected case %A" x
571+
ident |> getTypePat (set[]) t |> typeCheckPat
572+
| null -> PatWildcard catchNode
573+
565574
let exprFilterO = exprFilter |> Option.map descend
566575
let blockRes, block = descend block
567576
[ yield Some blockRes; yield exprFilterO |> Option.map fst ] |> Seq.choose id |> collectResults,
568-
(catchNode, ident |> getTypePat (set[]) t |> typeCheckPat, exprFilterO |> Option.map snd, block)
577+
(catchNode, basePat, exprFilterO |> Option.map snd, block)
569578

570579
let catches = catches |> List.map getMatch
571580
let finallyBodyO = finallyBody |> Option.ofObj |> Option.map descend

0 commit comments

Comments
 (0)