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
866b2723
Commit
866b2723
authored
Aug 12, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug186 - f(iota)
R=ken OCL=33051 CL=33051
parent
68e25051
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
4 deletions
+27
-4
go.h
src/cmd/gc/go.h
+1
-0
typecheck.c
src/cmd/gc/typecheck.c
+7
-3
walk.c
src/cmd/gc/walk.c
+1
-1
bug186.go
test/fixedbugs/bug186.go
+18
-0
No files found.
src/cmd/gc/go.h
View file @
866b2723
...
...
@@ -470,6 +470,7 @@ enum
Etype
=
1
<<
3
,
Ecall
=
1
<<
4
,
// call-only expressions are ok
Efnstruct
=
1
<<
5
,
// multivalue function returns are ok
Eiota
=
1
<<
6
,
// iota is ok
};
#define BITS 5
...
...
src/cmd/gc/typecheck.c
View file @
866b2723
...
...
@@ -85,6 +85,8 @@ reswitch:
*/
case
OLITERAL
:
ok
|=
Erv
;
if
(
n
->
iota
&&
!
(
top
&
Eiota
))
yyerror
(
"use of iota outside of constant initializer"
);
goto
ret
;
case
ONONAME
:
...
...
@@ -261,8 +263,8 @@ reswitch:
case
OSUB
:
case
OXOR
:
ok
|=
Erv
;
l
=
typecheck
(
&
n
->
left
,
Erv
);
r
=
typecheck
(
&
n
->
right
,
Erv
);
l
=
typecheck
(
&
n
->
left
,
Erv
|
(
top
&
Eiota
)
);
r
=
typecheck
(
&
n
->
right
,
Erv
|
(
top
&
Eiota
)
);
if
(
l
->
type
==
T
||
r
->
type
==
T
)
goto
error
;
op
=
n
->
op
;
...
...
@@ -339,7 +341,7 @@ reswitch:
case
ONOT
:
case
OPLUS
:
ok
|=
Erv
;
l
=
typecheck
(
&
n
->
left
,
Erv
);
l
=
typecheck
(
&
n
->
left
,
Erv
|
(
top
&
Eiota
)
);
if
((
t
=
l
->
type
)
==
T
)
goto
error
;
if
(
!
okfor
[
n
->
op
][
t
->
etype
])
{
...
...
@@ -995,6 +997,8 @@ error:
out:
lineno
=
lno
;
n
->
typecheck
=
1
;
if
(
n
->
iota
)
n
->
typecheck
=
0
;
*
np
=
n
;
return
n
;
}
...
...
src/cmd/gc/walk.c
View file @
866b2723
...
...
@@ -160,7 +160,7 @@ walkdef(Node *n)
dump
(
"walkdef nil defn"
,
n
);
yyerror
(
"xxx"
);
}
typecheck
(
&
e
,
Erv
);
typecheck
(
&
e
,
Erv
|
Eiota
);
if
(
e
->
op
!=
OLITERAL
)
{
yyerror
(
"const initializer must be constant"
);
goto
ret
;
...
...
test/fixedbugs/bug186.go
0 → 100644
View file @
866b2723
// errchk $G $D/$F.go
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
main
const
X
=
iota
func
f
(
x
int
)
{
}
func
main
()
{
f
(
X
);
f
(
iota
);
// ERROR "iota.*outside.*initializer"
f
(
X
);
f
(
iota
);
// ERROR "iota.*outside.*initializer"
}
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