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
d436a701
Commit
d436a701
authored
Jul 06, 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
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
10 deletions
+22
-10
src/cmd/gc/subr.c
src/cmd/gc/subr.c
+2
-2
src/cmd/gc/walk.c
src/cmd/gc/walk.c
+8
-1
src/pkg/http/client.go
src/pkg/http/client.go
+1
-3
test/interface/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)
...
@@ -3136,10 +3136,10 @@ runifacechecks(void)
t
,
iface
,
m
->
sym
,
m
->
type
);
t
,
iface
,
m
->
sym
,
m
->
type
);
else
if
(
!
p
->
explicit
&&
needexplicit
)
{
else
if
(
!
p
->
explicit
&&
needexplicit
)
{
if
(
m
)
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
);
p
->
src
,
p
->
dst
,
m
->
sym
,
m
->
type
);
else
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
);
p
->
src
,
p
->
dst
);
}
}
}
}
...
...
src/cmd/gc/walk.c
View file @
d436a701
...
@@ -1275,7 +1275,6 @@ walkconv(Node *n)
...
@@ -1275,7 +1275,6 @@ walkconv(Node *n)
// if using .(T), interface assertion.
// if using .(T), interface assertion.
if
(
n
->
op
==
ODOTTYPE
)
{
if
(
n
->
op
==
ODOTTYPE
)
{
// interface conversion
defaultlit
(
l
,
T
);
defaultlit
(
l
,
T
);
if
(
!
isinter
(
l
->
type
))
if
(
!
isinter
(
l
->
type
))
yyerror
(
"type assertion requires interface on left, have %T"
,
l
->
type
);
yyerror
(
"type assertion requires interface on left, have %T"
,
l
->
type
);
...
@@ -1309,6 +1308,14 @@ walkconv(Node *n)
...
@@ -1309,6 +1308,14 @@ walkconv(Node *n)
return
;
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
// simple fix-float
if
(
isint
[
l
->
type
->
etype
]
||
isfloat
[
l
->
type
->
etype
])
if
(
isint
[
l
->
type
->
etype
]
||
isfloat
[
l
->
type
->
etype
])
if
(
isint
[
t
->
etype
]
||
isfloat
[
t
->
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) {
...
@@ -130,9 +130,7 @@ func send(req *Request) (resp *Response, err os.Error) {
resp
.
AddHeader
(
key
,
value
);
resp
.
AddHeader
(
key
,
value
);
}
}
// TODO(rsc): Make this work:
r
:=
io
.
Reader
(
reader
);
// r := io.Reader(reader);
var
r
io
.
Reader
=
reader
;
if
v
:=
resp
.
GetHeader
(
"Transfer-Encoding"
);
v
==
"chunked"
{
if
v
:=
resp
.
GetHeader
(
"Transfer-Encoding"
);
v
==
"chunked"
{
r
=
newChunkedReader
(
reader
);
r
=
newChunkedReader
(
reader
);
}
}
...
...
test/interface/explicit.go
View file @
d436a701
...
@@ -15,13 +15,14 @@ type I interface { M() }
...
@@ -15,13 +15,14 @@ type I interface { M() }
var
i
I
var
i
I
type
I2
interface
{
M
();
N
();
}
type
I2
interface
{
M
();
N
();
}
var
i2
I2
;
var
i2
I2
var
e
interface
{
};
type
E
interface
{
}
var
e
E
func
main
()
{
func
main
()
{
e
=
t
;
// ok
e
=
t
;
// ok
t
=
e
;
// ERROR "need explicit"
t
=
e
;
// ERROR "need explicit
|need type assertion
"
// neither of these can work,
// neither of these can work,
// because i has an extra method
// because i has an extra method
...
@@ -30,5 +31,11 @@ func main() {
...
@@ -30,5 +31,11 @@ func main() {
t
=
i
;
// ERROR "missing|incompatible|is not"
t
=
i
;
// ERROR "missing|incompatible|is not"
i
=
i2
;
// ok
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