Skip to content

reflect: should not be allowed to invoke methods on unexported embedded fields #38521

@mdempsky

Description

@mdempsky

Test program: https://play.golang.org/p/Jnga2_6Rmdf

Currently the v.M() and v.u.M() calls successfully print "M", but the v.u2.M() call panics due to accessing an unexported field.

I think the v.u.M() line should also panic. v.u is unexported just like v.u2, and the promoted method is already exposed on v's method set, so there's no need to be able to invoke v.u.M() via reflection. (This distinguishes it from accessing promoted fields, which requires allowing traversal through unexported fields.)

I think reflect.Value.Method should have been updated to use v.flag.ro() in golang.org/cl/66331 like all the other methods. I suspect I just overlooked it because it didn't fit the pattern of all the other cases.

/cc @ianlancetaylor

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions