Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix isRecursive binding in ServiceParseTreeWalk.fs #14518

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
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"