-
Notifications
You must be signed in to change notification settings - Fork 789
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
defaultTraverse
for SynPat
in SyntaxTraverse.Traverse
doesn't walk down all SynPat
s
#13114
Comments
You're right. For other patterns it's of course still the case I cannot find |
Now I am sorry :P. It's not part of the default traverse, but I am overriding it in a custom walker. I don't see why |
I'm currently trying to detect if parens are necessary when a type annotation gets added. match ... with
| { Data = 42; Value = value } -> ()
| _ -> () To get to And: It's unexpected when it doesn't go down a path. It should at least be documented which elements gets traversed and which don't.
The issue with a custom walker is: There's no available default traversal member _.VisitPat (_, _, pat) =
match pat with
| SynPat.IsInst(pat=pat: SynType) -> ...
| _ -> ... -> We have to traverse But to go further down we have to implement more traversals: And And now we basically have our own hmm...maybe BTW: same issue when you want to select something that's not traversed by default. |
Necessary because of bugs and missing features: * Doesn't go into `SynMatchClause` * Fixed in `dotnet/fsharp` main, but not in just released FCS `41.0.4` (I think) * Doesn't walk into `SynPat.As` & `SynPat.Record` * `SynPat.As` gets visited in `dotnet/fsharp` main, not not in FCS `41.0.4` * `SynPat.Record`: dotnet/fsharp#13114 -> Remove `ServiceParseTreeWalk` once FCS gets updated (probably `42.0`? -> lots of changes of Syntax Elements)
Necessary because of bugs and missing features: * Doesn't go into `SynMatchClause` * Fixed in `dotnet/fsharp` main, but not in just released FCS `41.0.4` (I think) * Doesn't walk into `SynPat.As` & `SynPat.Record` * `SynPat.As` gets visited in `dotnet/fsharp` main, not not in FCS `41.0.4` * `SynPat.Record`: dotnet/fsharp#13114 -> Remove `ServiceParseTreeWalk` once FCS gets updated (probably `42.0`? -> lots of changes of Syntax Elements)
Necessary because of bugs and missing features: * Doesn't go into `SynMatchClause` * Fixed in `dotnet/fsharp` main, but not in just released FCS `41.0.4` (I think) * Doesn't walk into `SynPat.As` & `SynPat.Record` * `SynPat.As` gets visited in `dotnet/fsharp` main, not not in FCS `41.0.4` * `SynPat.Record`: dotnet/fsharp#13114 -> Remove `ServiceParseTreeWalk` once FCS gets updated (probably `42.0`? -> lots of changes of Syntax Elements)
Necessary because of bugs and missing features: * Doesn't go into `SynMatchClause` * Fixed in `dotnet/fsharp` main, but not in just released FCS `41.0.4` (I think) * Doesn't walk into `SynPat.As` & `SynPat.Record` * `SynPat.As` gets visited in `dotnet/fsharp` main, not not in FCS `41.0.4` * `SynPat.Record`: dotnet/fsharp#13114 -> Remove `ServiceParseTreeWalk` once FCS gets updated (probably `42.0`? -> lots of changes of Syntax Elements)
SyntaxTraverse.Traverse(pos, ast, SyntaxVisitorBase<_>)
passesdefaultTraverse
to allvisitor.VisitXXX(...)
-> implementation ofSyntaxVisitorBase
doesn't have to handle all Syntax constructs, but can pass current element on todefaultTraverse
.But for
SynPat
s (VisitPat
),defaultTraverse
doesn't handle all cases with nested Syntax:traversePat.defaultTraverse
is missing:SynPat.As(lhsPat: SynPat; rhsPat: SynPat)
SynPat.Record(fieldPats: (_*_*SynPat) list
SynPat.IsInst(pat: SynType)
SynPat.QuoteExpr(expr: SynExpr)
SynPat.FromParseError(pat: SynPat)
)Repro steps
Given F# source (->
text=
):and seeking
SynPat.Named
that starts withvalue
:source with nuget package (without
SynPat.Record
example)(unfortunately not as single Script File for F# interactive because I ran into #12703)
source for current main (with
SynPat.Record
example)Expected behavior
Walk down to each
value
and output:Actual behavior
Only finds first
Named
:(current nuget package)
and doesn't find
Record
on current main:Known workarounds
Custom handling of
SynPat.As
SynPat.Record
(etc. when necessary).But I think we now have to custom handle everything because
defaultTraverse
isSynPat
VisitPat
invocation (-> just for current pat, but not its children)traverseXXX
is exposed (-> cannot get back intoSyntaxTraversal.Traverse.traverseXXX
calls)(
traverseSynExpr
exposes itself tovisitor.VisitExpr
-- maybe there's a way to always expose alltraverseXXX
functions to visitors so visitor implementation can handle children?)Related information
Provide any related information (optional):
dotnet --version
:6.0.202
Edit:
SynPat.As
is handled in current main (#13114 (comment))-> Updated example to include
SynPat.Record
The text was updated successfully, but these errors were encountered: