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
480f5124
Commit
480f5124
authored
Jun 25, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug165
R=ken OCL=30783 CL=30783
parent
a0bcaf4c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
7 deletions
+31
-7
src/cmd/gc/dcl.c
src/cmd/gc/dcl.c
+11
-0
src/cmd/gc/go.h
src/cmd/gc/go.h
+2
-0
src/cmd/gc/subr.c
src/cmd/gc/subr.c
+13
-2
test/fixedbugs/bug165.go
test/fixedbugs/bug165.go
+5
-1
test/golden.out
test/golden.out
+0
-4
No files found.
src/cmd/gc/dcl.c
View file @
480f5124
...
...
@@ -93,6 +93,7 @@ updatetype(Type *n, Type *t)
{
Sym
*
s
;
int
local
;
int
maplineno
,
lno
;
s
=
n
->
sym
;
if
(
s
==
S
||
s
->
def
==
N
||
s
->
def
->
op
!=
OTYPE
||
s
->
def
->
type
!=
n
)
...
...
@@ -124,6 +125,7 @@ updatetype(Type *n, Type *t)
// type n t;
// copy t, but then zero out state associated with t
// that is no longer associated with n.
maplineno
=
n
->
maplineno
;
local
=
n
->
local
;
*
n
=
*
t
;
n
->
sym
=
s
;
...
...
@@ -133,6 +135,7 @@ updatetype(Type *n, Type *t)
n
->
method
=
nil
;
n
->
vargen
=
0
;
n
->
nod
=
N
;
// catch declaration of incomplete type
switch
(
n
->
etype
)
{
case
TFORWSTRUCT
:
...
...
@@ -141,6 +144,14 @@ updatetype(Type *n, Type *t)
default:
checkwidth
(
n
);
}
// double-check use of type as map key
if
(
maplineno
)
{
lno
=
lineno
;
lineno
=
maplineno
;
maptype
(
n
,
types
[
TBOOL
]);
lineno
=
lno
;
}
}
...
...
src/cmd/gc/go.h
View file @
480f5124
...
...
@@ -171,6 +171,8 @@ struct Type
// TARRAY
int32
bound
;
// negative is dynamic array
int32
maplineno
;
// first use of TFORW as map key
};
#define T ((Type*)0)
...
...
src/cmd/gc/subr.c
View file @
480f5124
...
...
@@ -345,8 +345,19 @@ maptype(Type *key, Type *val)
{
Type
*
t
;
if
(
key
!=
nil
&&
key
->
etype
!=
TANY
&&
algtype
(
key
)
==
ANOEQ
)
yyerror
(
"invalid map key type %T"
,
key
);
if
(
key
!=
nil
&&
key
->
etype
!=
TANY
&&
algtype
(
key
)
==
ANOEQ
)
{
if
(
key
->
etype
==
TFORW
)
{
// map[key] used during definition of key.
// postpone check until key is fully defined.
// if there are multiple uses of map[key]
// before key is fully defined, the error
// will only be printed for the first one.
// good enough.
if
(
key
->
maplineno
==
0
)
key
->
maplineno
=
lineno
;
}
else
yyerror
(
"invalid map key type %T"
,
key
);
}
t
=
typ
(
TMAP
);
t
->
down
=
key
;
t
->
type
=
val
;
...
...
test/bugs/bug165.go
→
test/
fixed
bugs/bug165.go
View file @
480f5124
...
...
@@ -7,5 +7,9 @@
package
main
type
I
interface
{
m
(
map
[
I
]
bool
)
m
(
map
[
I
]
bool
);
// ok
}
type
S
struct
{
m
map
[
S
]
bool
;
// ERROR "map key type"
}
test/golden.out
View file @
480f5124
...
...
@@ -111,10 +111,6 @@ BUG: should not compile
=========== bugs/bug164.go
BUG: should not compile
=========== bugs/bug165.go
bugs/bug165.go:6: invalid map key type I
BUG: should compile
=========== fixedbugs/bug016.go
fixedbugs/bug016.go:7: constant -3 overflows uint
...
...
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