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

text/template/parse: External types can still satisfy Node interface. #5482

Closed
gopherbot opened this issue May 15, 2013 · 3 comments
Closed

Comments

@gopherbot
Copy link

by KevinCathcart:

This is pretty minor, but http://golang.org/pkg/text/template/parse/#Node claims
"The interface contains an unexported method so that only types local to this
package can satisfy it."

One can still create new node types by embedding the Pos type, which includes the
unexported method. 

Proof of concept: http://play.golang.org/p/ssJ7FmjrZJ

Even if that loophole is closed, one can always embed a full Node type in order to
implement the interface.

You may not want to actually change any of this, but I thought it worth pointing out.
@rsc
Copy link
Contributor

rsc commented May 24, 2013

Comment 1:

True enough, thanks. Not much we can do about that, but at least it's harder to do
accidentally.

Status changed to Unfortunate.

@DanielMorsing
Copy link
Contributor

Comment 2:

This seems weird to me. Spec says that only when x.f is a legal selector would the field
or method f be promoted. Since the method is not exported, the selector is not legal and
the method should not be promoted.

@gopherbot
Copy link
Author

Comment 3 by KevinCathcart:

Daniel:
"A field or method f of an anonymous field in a struct x is called promoted if x.f is a
legal selector that denotes that field or method f."
That defines promotion, but it does not say anything about whether a field gets promoted
or not. It only says if the selector lookup rules result in choosing the same same field
or method as in the nested struct, then we call that field/method  promoted. It is a
passive definition.
The rest of that section states the additional rules for determining the method set of
the outer struct. It relies on the selector lookup rules working in conjunction with the
passive promotion definition to ensure method in the method set has a unique name.
One can reach two consistent states from this. One is assuming that "x.f" is an illegal
selector if f is non-exported, and is from a different package.
That conclusion is problematic, because the spec never actually says that. Indeed, the
only prohibitions in the spec on using non-exported identifiers from another package,
are that:
a) they cannot be referenced as a qualified identifier, and
b) that struct literals cannot initialize the value of non-exported fields. 
The other option is for "x.f" to be interpreted abstractly. In that case, the f could be
an non-exported method from some other package without any issue. One cannot refer to
such a method in the concrete syntax, due to the identifier uniqueness rules, but that
would permit the method being promoted. As far as I can tell, that is exactly the
interpretation used by the compiler.
I spent a long time thinking through these things prior to reporting this.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
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