Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
74ee51ee
Commit
74ee51ee
authored
Feb 06, 2012
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/gc: disallow switch _ := v.(type)
Fixes #2827. R=ken2 CC=golang-dev
https://golang.org/cl/5638045
parent
98257750
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
2 deletions
+6
-2
src/cmd/gc/go.y
src/cmd/gc/go.y
+1
-1
src/cmd/gc/y.tab.c
src/cmd/gc/y.tab.c
+1
-1
test/typeswitch3.go
test/typeswitch3.go
+4
-0
No files found.
src/cmd/gc/go.y
View file @
74ee51ee
...
...
@@ -423,7 +423,7 @@ simple_stmt:
yyerror("expr.(type) must be alone in list");
if($1->next != nil)
yyerror("argument count mismatch: %d = %d", count($1), 1);
else if(
$1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME
)
else if(
($1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME) || isblank($1->n)
)
yyerror("invalid variable name %N in type switch", $1->n);
else
$$->left = dclname($1->n->sym); // it'
s
a
colas
,
so
must
not
re
-
use
an
oldname
.
...
...
src/cmd/gc/y.tab.c
View file @
74ee51ee
...
...
@@ -2714,7 +2714,7 @@ yyreduce:
yyerror
(
"expr.(type) must be alone in list"
);
if
((
yyvsp
[(
1
)
-
(
3
)].
list
)
->
next
!=
nil
)
yyerror
(
"argument count mismatch: %d = %d"
,
count
((
yyvsp
[(
1
)
-
(
3
)].
list
)),
1
);
else
if
((
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
ONAME
&&
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
OTYPE
&&
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
ONONAME
)
else
if
((
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
ONAME
&&
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
OTYPE
&&
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
op
!=
ONONAME
)
||
isblank
((
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
)
)
yyerror
(
"invalid variable name %N in type switch"
,
(
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
);
else
(
yyval
.
node
)
->
left
=
dclname
((
yyvsp
[(
1
)
-
(
3
)].
list
)
->
n
->
sym
);
// it's a colas, so must not re-use an oldname.
...
...
test/typeswitch3.go
View file @
74ee51ee
...
...
@@ -30,6 +30,10 @@ func main(){
switch
r
.
(
type
)
{
case
io
.
Writer
:
}
// Issue 2827.
switch
_
:=
r
.
(
type
)
{
// ERROR "invalid variable name _"
}
}
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