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
c36fbdf7
Commit
c36fbdf7
authored
Aug 24, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fix for multiple fields at same depth error
R=rsc DELTA=9 (5 added, 0 deleted, 4 changed) OCL=33768 CL=33785
parent
89f69bb3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
type.go
src/pkg/reflect/type.go
+9
-4
No files found.
src/pkg/reflect/type.go
View file @
c36fbdf7
...
@@ -522,6 +522,7 @@ func (t *StructType) fieldByName(name string, mark map[*StructType]bool, depth i
...
@@ -522,6 +522,7 @@ func (t *StructType) fieldByName(name string, mark map[*StructType]bool, depth i
mark
[
t
]
=
true
;
mark
[
t
]
=
true
;
var
fi
int
;
// field index
var
fi
int
;
// field index
n
:=
0
;
// number of matching fields at depth fd
L
:
for
i
,
_
:=
range
t
.
fields
{
L
:
for
i
,
_
:=
range
t
.
fields
{
f
:=
t
.
Field
(
i
);
f
:=
t
.
Field
(
i
);
d
:=
inf
;
d
:=
inf
;
...
@@ -538,7 +539,7 @@ L: for i, _ := range t.fields {
...
@@ -538,7 +539,7 @@ L: for i, _ := range t.fields {
case
ft
.
Name
()
==
name
:
case
ft
.
Name
()
==
name
:
// Matching anonymous top-level field.
// Matching anonymous top-level field.
d
=
depth
;
d
=
depth
;
case
fd
>
0
:
case
fd
>
depth
:
// No top-level field yet; look inside nested structs.
// No top-level field yet; look inside nested structs.
if
st
,
ok
:=
ft
.
(
*
StructType
);
ok
{
if
st
,
ok
:=
ft
.
(
*
StructType
);
ok
{
f
,
d
=
st
.
fieldByName
(
name
,
mark
,
depth
+
1
);
f
,
d
=
st
.
fieldByName
(
name
,
mark
,
depth
+
1
);
...
@@ -550,10 +551,11 @@ L: for i, _ := range t.fields {
...
@@ -550,10 +551,11 @@ L: for i, _ := range t.fields {
case
d
<
fd
:
case
d
<
fd
:
// Found field at shallower depth.
// Found field at shallower depth.
ff
,
fi
,
fd
=
f
,
i
,
d
;
ff
,
fi
,
fd
=
f
,
i
,
d
;
n
=
1
;
case
d
==
fd
:
case
d
==
fd
:
// More than one matching field at the same depth (or d, fd == inf).
// More than one matching field at the same depth (or d, fd == inf).
// Same as no field found.
// Same as no field found
at this depth
.
fd
=
inf
;
n
++
;
if
d
==
depth
{
if
d
==
depth
{
// Impossible to find a field at lower depth.
// Impossible to find a field at lower depth.
break
L
;
break
L
;
...
@@ -561,12 +563,15 @@ L: for i, _ := range t.fields {
...
@@ -561,12 +563,15 @@ L: for i, _ := range t.fields {
}
}
}
}
if
fd
<
inf
{
if
n
==
1
{
// Found matching field.
// Found matching field.
if
len
(
ff
.
Index
)
<=
depth
{
if
len
(
ff
.
Index
)
<=
depth
{
ff
.
Index
=
make
([]
int
,
depth
+
1
);
ff
.
Index
=
make
([]
int
,
depth
+
1
);
}
}
ff
.
Index
[
depth
]
=
fi
;
ff
.
Index
[
depth
]
=
fi
;
}
else
{
// None or more than one matching field found.
fd
=
inf
;
}
}
mark
[
t
]
=
false
,
false
;
mark
[
t
]
=
false
,
false
;
...
...
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