Skip to content

reflect: Value.FieldByName is returning a valid Value in case of a field collision #4355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
griesemer opened this issue Nov 6, 2012 · 3 comments
Milestone

Comments

@griesemer
Copy link
Contributor

package main

import "fmt"
import "reflect"

type (
    T1 struct{ X int }
    T2 struct{ T1 }
    T3 struct{ T2; Z int }
    T4 struct{ T2; Z int }
    T5 struct {
        T3
        T4
        Y int
    }
)

func main() {
    v := reflect.ValueOf(T5{})
    fmt.Println("X", v.FieldByName("X"))
    fmt.Println("Y", v.FieldByName("Y"))
    fmt.Println("Z", v.FieldByName("Z"))
}

should print:

X <invalid Value>
Y <int Value>
Z <invalid Value>

However, using gc, at tip, it prints:

<int Value>
<int Value>
<invalid Value>

play.golang.org produces the correct result ( http://play.golang.org/p/rBGZEubaNy ), as
does gccgo.

I suspect that gccgo and the playground use an older version of reflect.
@rsc
Copy link
Contributor

rsc commented Nov 7, 2012

Comment 1:

Nice.

@griesemer
Copy link
Contributor Author

Comment 2:

Possible solution: http://golang.org/cl/6821094

@griesemer
Copy link
Contributor Author

Comment 3:

This issue was closed by revision aa38801.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants