Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
58e19aa4
Commit
58e19aa4
authored
Jul 14, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go: require { } around else block
R=gri, ken, r CC=golang-dev
https://golang.org/cl/4721044
parent
3f53475c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
6 deletions
+13
-6
go_spec.html
doc/go_spec.html
+1
-1
go.y
src/cmd/gc/go.y
+3
-0
if.go
test/if.go
+9
-5
No files found.
doc/go_spec.html
View file @
58e19aa4
...
...
@@ -3762,7 +3762,7 @@ present, the "else" branch is executed.
</p>
<pre
class=
"ebnf"
>
IfStmt
= "if" [ SimpleStmt ";" ] Expression Block [ "else" Statement
] .
IfStmt
= "if" [ SimpleStmt ";" ] Expression Block [ "else" ( IfStmt | Block )
] .
</pre>
<pre>
...
...
src/cmd/gc/go.y
View file @
58e19aa4
...
...
@@ -1462,6 +1462,9 @@ non_dcl_stmt:
}
|
if_stmt
LELSE
stmt
{
if
($
3
->
op
!= OIF && $3->op != OBLOCK)
yyerror
(
"missing { } after else"
);
popdcl
();
$$
=
$
1
;
$$->
nelse
=
list1
($
3
);
...
...
test/if.go
View file @
58e19aa4
...
...
@@ -53,25 +53,28 @@ func main() {
count
=
0
if
true
{
count
=
count
+
1
}
else
}
else
{
count
=
count
-
1
}
assertequal
(
count
,
1
,
"if else true"
)
count
=
0
if
false
{
count
=
count
+
1
}
else
}
else
{
count
=
count
-
1
}
assertequal
(
count
,
-
1
,
"if else false"
)
count
=
0
if
t
:=
1
;
false
{
if
t
:=
1
;
false
{
count
=
count
+
1
_
=
t
t
:=
7
_
=
t
}
else
}
else
{
count
=
count
-
t
}
assertequal
(
count
,
-
1
,
"if else false var"
)
count
=
0
...
...
@@ -80,8 +83,9 @@ func main() {
count
=
count
+
1
t
:=
7
_
=
t
}
else
}
else
{
count
=
count
-
t
}
_
=
t
assertequal
(
count
,
-
1
,
"if else false var outside"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment