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

Issue 1913041: code review 1913041: go_spec: don't allow parens around the literal type of ... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 7 months ago by gri
Modified:
14 years, 7 months ago
Reviewers:
CC:
golang-dev
Visibility:
Public.

Description

go_spec: don't allow parens around the literal type of composite literals Background: The current spec is imprecise with respect to the parsing ambiguity for composite literals: It says that the ambiguity arises when the TypeName form of the LiteralType is used. The following code: if (B) {} ... is not using the TypeName form (but the parenthesized TypeName form) and thus could be interpreted as: if ((B){}) ... instead of if B {} ... Both compilers and gofmt choose the latter interpretation. One could fix the spec by making the clause regarding the parsing ambiguity more precise ("...using the _possibly parenthesized_ TypeName form of the LiteralType..."). The alternative (chosen here) is to simply disallow parenthesized literal types. Except for a single test case (test/parentype.go) there appears to be no Go code under $GOROOT containing parenthesized literal types. Furthermore, parentheses are never needed around a literal type for correct parsing.

Patch Set 1 #

Patch Set 2 : code review 1913041: go_spec: don't allow parens around the literal type of ... #

Patch Set 3 : code review 1913041: go_spec: don't allow parens around the literal type of ... #

Patch Set 4 : code review 1913041: go_spec: don't allow parens around the literal type of ... #

Patch Set 5 : code review 1913041: go_spec: don't allow parens around the literal type of ... #

Unified diffs Side-by-side diffs Delta from patch set Stats (+6 lines, -7 lines) Patch
M doc/go_spec.html View 1 2 3 chunks +5 lines, -4 lines 0 comments Download
M test/parentype.go View 1 chunk +1 line, -3 lines 0 comments Download

Messages

Total messages: 4
gri
Hello golang-dev@googlegroups.com, I'd like you to review this change.
14 years, 7 months ago (2010-07-29 21:59:41 UTC) #1
r2
LGTM but let the compiler owners weigh in
14 years, 7 months ago (2010-07-29 22:05:46 UTC) #2
rsc1
LGTM simplifies the grammar in the spec. a little more complex in 6g but no ...
14 years, 7 months ago (2010-07-30 00:54:44 UTC) #3
gri
14 years, 7 months ago (2010-07-30 01:13:44 UTC) #4
*** Submitted as http://code.google.com/p/go/source/detail?r=f7210699ce96 ***

go_spec: don't allow parens around the literal type of composite literals

Background: The current spec is imprecise with respect to the parsing ambiguity
for composite literals: It says that the ambiguity arises when the TypeName form
of the LiteralType is used. The following code:

    if (B) {} ...

is not using the TypeName form (but the parenthesized TypeName form) and thus
could be interpreted as:

    if ((B){}) ...

instead of

    if B {} ...

Both compilers and gofmt choose the latter interpretation. One could fix the
spec by making the clause regarding the parsing ambiguity more precise
("...using
the _possibly parenthesized_ TypeName form of the LiteralType..."). The
alternative
(chosen here) is to simply disallow parenthesized literal types. Except for a
single
test case (test/parentype.go) there appears to be no Go code under $GOROOT
containing
parenthesized literal types. Furthermore, parentheses are never needed around a
literal type for correct parsing.

R=golang-dev
CC=golang-dev
http://codereview.appspot.com/1913041
Sign in to reply to this message.

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