-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: StructOf.Implements is true for embedded unexported methods #20633
Comments
At tip the result is:
|
This isn't a dup of already-fixed #20541? |
The difference is that types in the original issue are hand-written and the types in this issue are generated by |
This is another aspect of #15924. Closing in favor of that one. Please comment if you disagree. |
I think this issue is slightly different. The problem here isn't the lack of wrapper methods but that the output of |
Ah, I see. In that case, I believe that this would be fixed on tip by the fix to #20541, if it weren't for the fact that the fix for #18780 means that you can no longer use
Based on that I think this is fixed. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
If you create an interface with an unexported method and another type in the
same package that implements that interface, you can embed that type in a
struct to have that struct also implement that interface.
If you generate a struct with
reflect.StructOf
, the generated type claims toalso implement that interface but cannot be casted to it.
https://play.golang.org/p/QPlzjnwiZc demonstrates this by generating a type
which embeds
*ast.Ident
. The generated type claims to implementast.Expr
but a value of that type cannot actually be casted to
ast.Expr
.What did you expect to see?
Note that based on the documentation of
reflect.StructOf
, the expectationis that the type does NOT implement
ast.Expr
:What did you see instead?
The type claims to implement the interface but instances of that type cannot
be cast into that interface.
Worth mentioning that if the method on the interface is exported, the
generated type claims to implement the interface and can be casted to it. This
goes against what the docs state but it's a separate issue. See #20632.
Possibly related: #20541
The text was updated successfully, but these errors were encountered: