You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/vet: detect impossible interface-interface type assertions #4483
For:
$ cat test.go
package main
import "io"
func main() {
var y interface {
Read()
}
_ = y.(io.Reader)
}
Neither compiler complains:
$ gccgo test.go
$ go tool 6g test.go
And according to the spec it is a valid program.
However, any concrete value assigned to y must implement Read(), and thus cannot
possibly implement io.Reader.Read. Thus, this type assertion will fail and we know this
at compile time.
The spec should require this check and compilers should implement it. This would be a
backward-incompatible language change, albeit with a very small chance of actually
breaking existing code.
From issue #8610, a point to consider:
When it comes to interface assignments ("implements" relation), conflicting method
signatures are not permitted.
Activity
rsc commentedon Dec 6, 2012
Comment 1:
rsc commentedon Jul 30, 2013
Comment 2:
Labels changed: added go2.
rsc commentedon Dec 4, 2013
Comment 3:
Labels changed: added repo-main.
griesemer commentedon Feb 27, 2014
Comment 4:
Status changed to LongTerm.
griesemer commentedon Aug 25, 2014
Comment 5:
Labels changed: added release-none.
griesemer commentedon Aug 28, 2014
Comment 6:
Issue #8610 has been merged into this issue.
griesemer commentedon Aug 28, 2014
Comment 7:
31 remaining items
toothrot commentedon May 14, 2020
@smasher164 @ianlancetaylor @griesemer: Does this issue need to be updated now that https://golang.org/cl/232660 is merged? It's labeled as blocking the Go 1.15 beta.
smasher164 commentedon May 14, 2020
@toothrot Since CL 232660 has been merged, this issue is resolved, and no longer a release blocker.
ianlancetaylor commentedon May 14, 2020
I'm planning to review this and #32479 to make sure they are done and to write release notes.
gopherbot commentedon May 18, 2020
Change https://golang.org/cl/234518 mentions this issue:
doc/go1.15: mention vet warning for impossible type assertionsdoc/go1.15: mention vet warning for impossible type assertions