Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3026)

Issue 8569045: code review 8569045: go/doc/example: Fix bug causing false negatives for Exa... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years ago by jeremiah
Modified:
10 years, 11 months ago
Reviewers:
CC:
adg, gobot, golang-dev, gri
Visibility:
Public.

Description

go/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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+87 lines, -0 lines) Patch
M src/pkg/go/doc/example.go View 1 2 3 4 1 chunk +7 lines, -0 lines 0 comments Download
M src/pkg/go/doc/example_test.go View 1 2 3 4 4 chunks +80 lines, -0 lines 0 comments Download

Messages

Total messages: 6
jeremiah
Hello gri@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
11 years ago (2013-04-26 18:40:13 UTC) #1
gri
Please also s/absract/abstract/ in the CL description. - gri https://codereview.appspot.com/8569045/diff/6001/src/pkg/go/doc/example.go File src/pkg/go/doc/example.go (right): https://codereview.appspot.com/8569045/diff/6001/src/pkg/go/doc/example.go#newcode170 src/pkg/go/doc/example.go:170: ...
11 years ago (2013-04-26 19:55:50 UTC) #2
jeremiah
Thanks for the review. Changes made and tests all pass. Also fixed description spelling issues. ...
11 years ago (2013-04-26 21:25:41 UTC) #3
gobot
R=adg (assigned by adg)
11 years ago (2013-04-29 07:58:57 UTC) #4
adg
LGTM
10 years, 11 months ago (2013-05-06 17:04:26 UTC) #5
adg
10 years, 11 months ago (2013-05-06 17:15:20 UTC) #6
*** Submitted as https://code.google.com/p/go/source/detail?r=17c26220ac96 ***

go/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  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  }

R=adg
CC=gobot, golang-dev, gri
https://codereview.appspot.com/8569045

Committer: Andrew Gerrand <adg@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b