You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I didn't see it documented, but found things like #547 that suggest that the syntax foo?.[0] can be used to allow optional array indexing.
I guess to step back, the problem I'm trying to solve is in my use case, I actually don't care about undefined parameters, and it would be nice, if I could just have everything be treated as nil, if not defined. That could be a distinct feature request, I suppose.
To get around this, I've decided to Patch the AST, I've been using this.
type walker struct {
}
func (a *walker) Visit(node *ast.Node) {
if n, ok := (*node).(*ast.MemberNode); ok {
v := *n
v.Optional = true
ast.Patch(node, &v)
}
}
I've also tried on a few test programs, but they all error with some variation of:
Case #2, suggests that the rewriting works correctly, as it was able to rewrite it (although maybe actually it didn't and the AllowUnedifiedVariables() is what is doing it).
Case #2,#4,#6,#8 suggest that I'm rewriting ... something, because I'm printing the output of the program .Node().String().
Case #1,#2 and #3, #4, suggest the rewritten syntax is correct (that is the patched AST has the same Node().String().
So I didn't see it documented, but found things like #547 that suggest that the syntax
foo?.[0]can be used to allow optional array indexing.I guess to step back, the problem I'm trying to solve is in my use case, I actually don't care about undefined parameters, and it would be nice, if I could just have everything be treated as nil, if not defined. That could be a distinct feature request, I suppose.
To get around this, I've decided to Patch the AST, I've been using this.
I've also tried on a few test programs, but they all error with some variation of:
Here is the output from my test program:
I believe it supports the following conclusions:
Case #2, suggests that the rewriting works correctly, as it was able to rewrite it (although maybe actually it didn't and the AllowUnedifiedVariables() is what is doing it).
Case #2,#4,#6,#8 suggest that I'm rewriting ... something, because I'm printing the output of the program
.Node().String().Case #1,#2 and #3, #4, suggest the rewritten syntax is correct (that is the patched AST has the same Node().String().
So the possible bugs I would like to suggest are:
Do let me know if I'm just doing something wrong.