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
d436a701
Commit
d436a701
authored
Jul 07, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow conversion to interface type
when implicit assignment would have been okay. R=ken OCL=31225 CL=31227
parent
53ebd163
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
10 deletions
+22
-10
subr.c
src/cmd/gc/subr.c
+2
-2
walk.c
src/cmd/gc/walk.c
+8
-1
client.go
src/pkg/http/client.go
+1
-3
explicit.go
test/interface/explicit.go
+11
-4
No files found.
src/cmd/gc/subr.c
View file @
d436a701
...
...
@@ -3136,10 +3136,10 @@ runifacechecks(void)
t
,
iface
,
m
->
sym
,
m
->
type
);
else
if
(
!
p
->
explicit
&&
needexplicit
)
{
if
(
m
)
yyerror
(
"need
explicit convers
ion to use %T as %T
\n\t
missing %S%hhT"
,
yyerror
(
"need
type assert
ion to use %T as %T
\n\t
missing %S%hhT"
,
p
->
src
,
p
->
dst
,
m
->
sym
,
m
->
type
);
else
yyerror
(
"need
explicit convers
ion to use %T as %T"
,
yyerror
(
"need
type assert
ion to use %T as %T"
,
p
->
src
,
p
->
dst
);
}
}
...
...
src/cmd/gc/walk.c
View file @
d436a701
...
...
@@ -1275,7 +1275,6 @@ walkconv(Node *n)
// if using .(T), interface assertion.
if
(
n
->
op
==
ODOTTYPE
)
{
// interface conversion
defaultlit
(
l
,
T
);
if
(
!
isinter
(
l
->
type
))
yyerror
(
"type assertion requires interface on left, have %T"
,
l
->
type
);
...
...
@@ -1309,6 +1308,14 @@ walkconv(Node *n)
return
;
}
// to/from interface.
// ifaceas1 will generate a good error
// if the conversion is invalid.
if
(
t
->
etype
==
TINTER
||
l
->
type
->
etype
==
TINTER
)
{
indir
(
n
,
ifacecvt
(
t
,
l
,
ifaceas1
(
t
,
l
->
type
,
0
)));
return
;
}
// simple fix-float
if
(
isint
[
l
->
type
->
etype
]
||
isfloat
[
l
->
type
->
etype
])
if
(
isint
[
t
->
etype
]
||
isfloat
[
t
->
etype
])
{
...
...
src/pkg/http/client.go
View file @
d436a701
...
...
@@ -130,9 +130,7 @@ func send(req *Request) (resp *Response, err os.Error) {
resp
.
AddHeader
(
key
,
value
);
}
// TODO(rsc): Make this work:
// r := io.Reader(reader);
var
r
io
.
Reader
=
reader
;
r
:=
io
.
Reader
(
reader
);
if
v
:=
resp
.
GetHeader
(
"Transfer-Encoding"
);
v
==
"chunked"
{
r
=
newChunkedReader
(
reader
);
}
...
...
test/interface/explicit.go
View file @
d436a701
...
...
@@ -15,13 +15,14 @@ type I interface { M() }
var
i
I
type
I2
interface
{
M
();
N
();
}
var
i2
I2
;
var
i2
I2
var
e
interface
{
};
type
E
interface
{
}
var
e
E
func
main
()
{
e
=
t
;
// ok
t
=
e
;
// ERROR "need explicit"
t
=
e
;
// ERROR "need explicit
|need type assertion
"
// neither of these can work,
// because i has an extra method
...
...
@@ -30,5 +31,11 @@ func main() {
t
=
i
;
// ERROR "missing|incompatible|is not"
i
=
i2
;
// ok
i2
=
i
;
// ERROR "need explicit"
i2
=
i
;
// ERROR "need explicit|need type assertion"
i
=
I
(
i2
);
// ok
i2
=
I2
(
i
);
// ERROR "need explicit|need type assertion"
e
=
E
(
t
);
// ok
t
=
T
(
e
);
// ERROR "need explicit|need type assertion"
}
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