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
4684df52
Commit
4684df52
authored
Apr 25, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc: explain why invalid receiver types are invalid
Fixes #1680. R=ken2 CC=golang-dev
https://golang.org/cl/4446061
parent
8698bb6c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
dcl.c
src/cmd/gc/dcl.c
+26
-0
method2.go
test/method2.go
+8
-2
No files found.
src/cmd/gc/dcl.c
View file @
4684df52
...
...
@@ -1139,6 +1139,32 @@ addmethod(Sym *sf, Type *t, int local)
pa
=
pa
->
type
;
f
=
methtype
(
pa
);
if
(
f
==
T
)
{
t
=
pa
;
if
(
t
!=
T
)
{
if
(
isptr
[
t
->
etype
])
{
if
(
t
->
sym
!=
S
)
{
yyerror
(
"invalid receiver type %T (%T is a pointer type)"
,
pa
,
t
);
return
;
}
t
=
t
->
type
;
}
}
if
(
t
!=
T
)
{
if
(
t
->
sym
==
S
)
{
yyerror
(
"invalid receiver type %T (%T is an unnamed type)"
,
pa
,
t
);
return
;
}
if
(
isptr
[
t
->
etype
])
{
yyerror
(
"invalid receiver type %T (%T is a pointer type)"
,
pa
,
t
);
return
;
}
if
(
t
->
etype
==
TINTER
)
{
yyerror
(
"invalid receiver type %T (%T is an interface type)"
,
pa
,
t
);
return
;
}
}
// Should have picked off all the reasons above,
// but just in case, fall back to generic error.
yyerror
(
"invalid receiver type %T"
,
pa
);
return
;
}
...
...
test/method2.go
View file @
4684df52
...
...
@@ -12,8 +12,14 @@ type T struct {
type
P
*
T
type
P1
*
T
func
(
p
P
)
val
()
int
{
return
1
}
// ERROR "receiver"
func
(
p
*
P1
)
val
()
int
{
return
1
}
// ERROR "receiver"
func
(
p
P
)
val
()
int
{
return
1
}
// ERROR "receiver.* pointer"
func
(
p
*
P1
)
val
()
int
{
return
1
}
// ERROR "receiver.* pointer"
type
I
interface
{}
type
I1
interface
{}
func
(
p
I
)
val
()
int
{
return
1
}
// ERROR "receiver.*interface"
func
(
p
*
I1
)
val
()
int
{
return
1
}
// ERROR "receiver.*interface"
type
Val
interface
{
val
()
int
...
...
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