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

spec: type assertion x.(T) where T is an interface should not permit conflicting method signatures #8610

Closed
griesemer opened this issue Aug 28, 2014 · 1 comment
Labels
FrozenDueToAge LanguageChange v2 A language change or incompatible library change

Comments

@griesemer
Copy link
Contributor

See also issue #8561.

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

compiles w/o a problem but leads to a guaranteed run-time failure: The method m in T1
and T2 have conflicting signatures and thus x (static type T1) cannot possibly be of
type T2.

The spec does not require that the signatures be conflict-free (
http://tip.golang.org/ref/spec#Type_assertions ):

"If T is an interface type, x.(T) asserts that the dynamic type of x implements the
interface T."

Interestingly, when it comes to interface assignments ("implements" relation),
conflicting method signatures are not permitted:

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

prog.go:13: cannot use x2 (type T2) as type T1 in assignment:
    T2 does not implement T1 (wrong type for m method)
        have m(string)
        want m(int)
prog.go:14: cannot use x1 (type T1) as type T2 in assignment:
    T1 does not implement T2 (wrong type for m method)
        have m(int)
        want m(string)
@griesemer
Copy link
Contributor Author

Comment 1:

Sigh. I knew I filed this one before.

Status changed to Duplicate.

Merged into issue #4483.

@griesemer griesemer added duplicate v2 A language change or incompatible library change LanguageChange labels Aug 28, 2014
@griesemer griesemer self-assigned this Aug 28, 2014
@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.
Labels
FrozenDueToAge LanguageChange v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

2 participants