Skip to content
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

reflect, unsafe: should provide access to non-exported methods #47356

Closed
fenginsc opened this issue Jul 23, 2021 · 6 comments
Closed

reflect, unsafe: should provide access to non-exported methods #47356

fenginsc opened this issue Jul 23, 2021 · 6 comments
Labels
FeatureRequest FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@fenginsc
Copy link

Hello everyone, after version 1.11, access to non-exported methods was cancelled, but from a flexibility point of view, access to non-exported methods should be provided.Other languages do the same, otherwise it feels limited to use.
Thanks.

@ianlancetaylor
Copy link
Contributor

What kind of access do you suggest?

Note that even before 1.11 the reflect package did not permit calling unexported methods.

@robpike
Copy link
Contributor

robpike commented Jul 23, 2021

The reflect package allows one to examine the types in a program. It is not intended to be a way to defeat the type system. It does not step outside the bounds of Go's types and values, it just allows one to write programs that work on types not known at compile time.

If the author of the package didn't want that method available, it does not matter what the mechanism is: it will not be available.

@fenginsc
Copy link
Author

fenginsc commented Jul 25, 2021

Maybe you don't think Java, which can provide private method calls, is very good?
Greatly increased flexibility, of course, this is only my view.

@beoran
Copy link

beoran commented Jul 25, 2021

Yes, I can only speak for myself but in my opinion Java is not very good if it allows to bypass the type system like this.

Edit: When learning Go it is better not to compare too much with other programming languages because Go does many things differently, for very good reasons.

@cagedmantis cagedmantis changed the title reflect or unsafe should provide access to non-exported methods. reflect, unsafe: should provide access to non-exported methods. Jul 28, 2021
@wdvxdr1123
Copy link
Contributor

Using unsafe and linkname, it's possible to call a non-exported method for now.

@dmitshur dmitshur changed the title reflect, unsafe: should provide access to non-exported methods. reflect, unsafe: should provide access to non-exported methods Aug 9, 2021
@dmitshur dmitshur added FeatureRequest WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 9, 2021
@dmitshur dmitshur added this to the Backlog milestone Aug 9, 2021
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

7 participants