Descriptiongo/doc/example: Fix bug causing false negatives for Example playability.
Allows Examples with KeyValue expressions to be playable in godoc.
During the traversal of the abstract syntax tree any KeyValueExpr Key.Name was incorrectly being added as an unresolved identifier.
Since this identifier could not be provided the Example was marked as unplayable.
This updates the AST traversal to skip Keys (but continue traversing the Values).
Example of problematic AST now fixed (see L99 where "UpperBound" was being added as a missing identifier):
81 . . . . . . . . . Values: []ast.Expr (len = 1) {
82 . . . . . . . . . . 0: *ast.UnaryExpr {
83 . . . . . . . . . . . OpPos: 12:19
84 . . . . . . . . . . . Op: &
85 . . . . . . . . . . . X: *ast.CompositeLit {
86 . . . . . . . . . . . . Type: *ast.SelectorExpr {
87 . . . . . . . . . . . . . X: *ast.Ident {
88 . . . . . . . . . . . . . . NamePos: 12:20
89 . . . . . . . . . . . . . . Name: "t_proto"
90 . . . . . . . . . . . . . }
91 . . . . . . . . . . . . . Sel: *ast.Ident {
92 . . . . . . . . . . . . . . NamePos: 12:41
93 . . . . . . . . . . . . . . Name: "BConfig"
94 . . . . . . . . . . . . . }
95 . . . . . . . . . . . . }
96 . . . . . . . . . . . . Lbrace: 12:79
97 . . . . . . . . . . . . Elts: []ast.Expr (len = 2) {
98 . . . . . . . . . . . . . 0: *ast.KeyValueExpr {
99 . . . . . . . . . . . . . . Key: *ast.Ident {
100 . . . . . . . . . . . . . . . NamePos: 13:3
101 . . . . . . . . . . . . . . . Name: "UpperBound"
102 . . . . . . . . . . . . . . }
103 . . . . . . . . . . . . . . Colon: 13:13
104 . . . . . . . . . . . . . . Value: *ast.CallExpr {
105 . . . . . . . . . . . . . . . Fun: *ast.SelectorExpr {
106 . . . . . . . . . . . . . . . . X: *ast.Ident {
107 . . . . . . . . . . . . . . . . . NamePos: 13:15
108 . . . . . . . . . . . . . . . . . Name: "proto"
109 . . . . . . . . . . . . . . . . }
110 . . . . . . . . . . . . . . . . Sel: *ast.Ident {
111 . . . . . . . . . . . . . . . . . NamePos: 13:21
112 . . . . . . . . . . . . . . . . . Name: "Float32"
113 . . . . . . . . . . . . . . . . }
Patch Set 1 #Patch Set 2 : diff -r 45c12efb4635 https://code.google.com/p/go #Patch Set 3 : diff -r 45c12efb4635 https://code.google.com/p/go #Patch Set 4 : diff -r 45c12efb4635 https://code.google.com/p/go #
Total comments: 4
Patch Set 5 : diff -r 45c12efb4635 https://code.google.com/p/go #Patch Set 6 : diff -r 8cca28e940ea https://code.google.com/p/go #MessagesTotal messages: 6
|