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

go/types: rejects type assertion incorrectly #8561

adonovan opened this issue Aug 20, 2014 · 4 comments

go/types: rejects type assertion incorrectly #8561

adonovan opened this issue Aug 20, 2014 · 4 comments


Copy link

Conversions between interfaces whose concrete types are provably disjoint should be an

gc performs a dynamic check; go/types rejects this program with this error:
a.go:9:6: i (variable of type interface{f(int)}) cannot have dynamic type
interface{f(string)} (wrong type for method f)

The spec doesn't say what should happen.  I think this should be a required error,
otherwise it makes "duck typing" very fragile, because adding a parameter to
one interface doesn't and recompiling doesn't detect that the other interface should
have been modified too.
Copy link
Member Author

Comment 1:

Sorry, that was reported in haste.   To clarify:
- this is about type assertions to interface types, not conversions.
- the spec doesn't mention the possibility of a static error, and does talk about
dynamic types,
   so gc is consistent with the spec and go/types is not.  Reassigning to gri.
- we probably couldn't change this even if we want to due to the Go 1.1 compatibility
guarantee (and I do want to, because the current behaviour is harmful since it creates
latent dynamic errors when changing one interface but not another.)
- s/interface doesn't/interface/

Owner changed to @griesemer.

Copy link

rsc commented Aug 25, 2014

Comment 2:

Status changed to Accepted.

Copy link

Comment 3:

Labels changed: added release-go1.4, repo-tools.

Copy link

Comment 4:

This issue was closed by revision golang/tools@289e96c.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

4 participants