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
1caaff6b
Commit
1caaff6b
authored
Feb 26, 2013
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/types: embedded fields can be predeclared types
R=adonovan, r CC=golang-dev
https://golang.org/cl/7376055
parent
d6a057c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
operand.go
src/pkg/go/types/operand.go
+10
-2
decls3.src
src/pkg/go/types/testdata/decls3.src
+22
-0
No files found.
src/pkg/go/types/operand.go
View file @
1caaff6b
...
...
@@ -300,7 +300,11 @@ func lookupFieldBreadthFirst(list []embeddedType, name QualifiedName) (res looku
// this level, f.Type appears multiple times at the next
// level.
if
f
.
IsAnonymous
&&
res
.
mode
==
invalid
{
next
=
append
(
next
,
embeddedType
{
deref
(
f
.
Type
)
.
(
*
NamedType
),
e
.
multiples
})
// Ignore embedded basic types - only user-defined
// named types can have methods or have struct fields.
if
t
,
_
:=
deref
(
f
.
Type
)
.
(
*
NamedType
);
t
!=
nil
{
next
=
append
(
next
,
embeddedType
{
t
,
e
.
multiples
})
}
}
}
...
...
@@ -377,7 +381,11 @@ func lookupField(typ Type, name QualifiedName) lookupResult {
// Possible optimization: If the embedded type
// is a pointer to the current type we could
// ignore it.
next
=
append
(
next
,
embeddedType
{
typ
:
deref
(
f
.
Type
)
.
(
*
NamedType
)})
// Ignore embedded basic types - only user-defined
// named types can have methods or have struct fields.
if
t
,
_
:=
deref
(
f
.
Type
)
.
(
*
NamedType
);
t
!=
nil
{
next
=
append
(
next
,
embeddedType
{
typ
:
t
})
}
}
}
if
len
(
next
)
>
0
{
...
...
src/pkg/go/types/testdata/decls3.src
View file @
1caaff6b
...
...
@@ -44,6 +44,28 @@ func issue4355() {
_
=
t
/*
ERROR
"no single field or method"
*/
.
X
}
//
Embedded
fields
can
be
predeclared
types
.
func
_
()
{
type
T0
struct
{
int
float32
f
int
}
var
x
T0
_
=
x
.
int
_
=
x
.
float32
_
=
x
.
f
type
T1
struct
{
T0
}
var
y
T1
_
=
y
.
int
_
=
y
.
float32
_
=
y
.
f
}
//
Borrowed
from
the
FieldByName
test
cases
in
reflect
/
all_test
.
go
.
type
D1
struct
{
...
...
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