Skip to content

Commit

Permalink
fix isRecursive binding in ServiceParseTreeWalk.fs (#14518)
Browse files Browse the repository at this point in the history
* fix isRecursive binding in ServiceParseTreeWalk.fs

* use named access on ident pattern match
  • Loading branch information
rosskuehl authored Jan 4, 2023
1 parent cd09ee2 commit a9b3ea5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceParseTreeWalk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ module SyntaxTraversal =

| SynExpr.TypeApp (synExpr, _, _synTypeList, _commas, _, _, _range) -> traverseSynExpr synExpr

| SynExpr.LetOrUse (_, isRecursive, synBindingList, synExpr, range, _) ->
| SynExpr.LetOrUse (isRecursive, _, synBindingList, synExpr, range, _) ->
match visitor.VisitLetOrUse(path, isRecursive, traverseSynBinding path, synBindingList, range) with
| None ->
[
Expand Down
18 changes: 17 additions & 1 deletion tests/service/TreeVisitorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@ let ``Visit enum definition test`` () =

match SyntaxTraversal.Traverse(pos0, parseTree, visitor) with
| Some [ SynEnumCase (_, SynIdent(id1,_), _, _, _, _, _); SynEnumCase (_, SynIdent(id2,_), _, _, _, _, _) ] when id1.idText = "A" && id2.idText = "B" -> ()
| _ -> failwith "Did not visit enum definition"
| _ -> failwith "Did not visit enum definition"

[<Test>]
let ``Visit recursive let binding`` () =
let visitor =
{ new SyntaxVisitorBase<_>() with
member x.VisitExpr(_, _, defaultTraverse, expr) = defaultTraverse expr
member x.VisitLetOrUse(_, isRecursive, _, bindings, _) =
if not isRecursive then failwith $"{nameof isRecursive} should be true"
Some bindings }

let source = "let rec fib n = if n < 2 then n else fib (n - 1) + fib (n - 2) in fib 10"
let parseTree = parseSourceCode("C:\\test.fs", source)

match SyntaxTraversal.Traverse(pos0, parseTree, visitor) with
| Some [ SynBinding(valData = SynValData(valInfo = SynValInfo(curriedArgInfos = [ [ SynArgInfo(ident = Some id) ] ]))) ] when id.idText = "n" -> ()
| _ -> failwith "Did not visit recursive let binding"

0 comments on commit a9b3ea5

Please sign in to comment.