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

Closed
adonovan opened this issue Aug 20, 2014 · 4 comments
Closed

go/types: rejects type assertion incorrectly #8561

adonovan opened this issue Aug 20, 2014 · 4 comments
Assignees
Milestone

Comments

@adonovan
Copy link
Contributor

@adonovan adonovan commented Aug 20, 2014

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

http://play.golang.org/p/v8hmUJ909X

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.
@adonovan
Copy link
Contributor Author

@adonovan adonovan commented Aug 20, 2014

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.

Loading

@rsc
Copy link
Contributor

@rsc rsc commented Aug 25, 2014

Comment 2:

Status changed to Accepted.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 27, 2014

Comment 3:

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

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 28, 2014

Comment 4:

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

Status changed to Fixed.

Loading

@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants