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

Correct body SynExpr of parsedData of Lambda when wildcards are involved. #11781

Merged
merged 3 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/fsharp/SyntaxTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,15 @@ let rec SimplePatOfPat (synArgNameGenerator: SynArgNameGenerator) p =
let id = mkSynId m nm
let item = mkSynIdGet m nm
true, None, id, item
SynSimplePat.Id (id, altNameRefCell, isCompGen, false, false, id.idRange),
Some (fun e ->
let clause = SynMatchClause(p, None, e, m, DebugPointForTarget.No)
SynExpr.Match (DebugPointAtBinding.NoneAtInvisible, item, [clause], clause.Range))
let fn =
match p with
| SynPat.Wild _ -> None
| _ ->
Some (fun e ->
let clause = SynMatchClause(p, None, e, m, DebugPointForTarget.No)
SynExpr.Match (DebugPointAtBinding.NoneAtInvisible, item, [clause], clause.Range))

SynSimplePat.Id (id, altNameRefCell, isCompGen, false, false, id.idRange), fn

let appFunOpt funOpt x = match funOpt with None -> x | Some f -> f x

Expand Down
61 changes: 61 additions & 0 deletions tests/service/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,4 +1225,65 @@ module ParsedHashDirective =
]) ])) ->
Assert.AreEqual("40", v)
assertRange (1, 8) (1, 16) m
| _ -> Assert.Fail "Could not get valid AST"

module Lambdas =
[<Test>]
let ``Lambda with two parameters gives correct body`` () =
let parseResults =
getParseResults
"fun a b -> x"

match parseResults with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [
SynModuleDecl.DoExpr(
expr = SynExpr.Lambda(parsedData = Some([SynPat.Named _; SynPat.Named _], SynExpr.Ident(ident)))
)
]) ])) ->
Assert.AreEqual("x", ident.idText)
| _ -> Assert.Fail "Could not get valid AST"

[<Test>]
let ``Lambda with wild card parameter gives correct body`` () =
let parseResults =
getParseResults
"fun a _ b -> x"

match parseResults with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [
SynModuleDecl.DoExpr(
expr = SynExpr.Lambda(parsedData = Some([SynPat.Named _; SynPat.Wild _; SynPat.Named _], SynExpr.Ident(ident)))
)
]) ])) ->
Assert.AreEqual("x", ident.idText)
| _ -> Assert.Fail "Could not get valid AST"

[<Test>]
let ``Lambda with tuple parameter with wild card gives correct body`` () =
let parseResults =
getParseResults
"fun a (b, _) c -> x"

match parseResults with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [
SynModuleDecl.DoExpr(
expr = SynExpr.Lambda(parsedData = Some([SynPat.Named _; SynPat.Paren(SynPat.Tuple _,_); SynPat.Named _], SynExpr.Ident(ident)))
)
]) ])) ->
Assert.AreEqual("x", ident.idText)
| _ -> Assert.Fail "Could not get valid AST"

[<Test>]
let ``Lambda with wild card that returns a lambda gives correct body`` () =
let parseResults =
getParseResults
"fun _ -> fun _ -> x"

match parseResults with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [
SynModuleDecl.DoExpr(
expr = SynExpr.Lambda(parsedData = Some([SynPat.Wild _], SynExpr.Lambda(parsedData = Some([SynPat.Wild _], SynExpr.Ident(ident)))))
)
]) ])) ->
Assert.AreEqual("x", ident.idText)
| _ -> Assert.Fail "Could not get valid AST"