Skip to content

spec: semantics of recursive interfaces are unspecified #8691

@adonovan

Description

@adonovan
I can't find any wording in the spec that would explain the legality or otherwise of
this program.  The question is whether isomorphic recursive interfaces are identical and
thus mutually assignable.   My intuition about interfaces would suggest that these types
ought to be identical.

http://play.golang.org/p/r92J5TY-WI

package main 

type I interface {
    f() I
}
type J interface {
    f() J
}

func main() {
    var i I
    var j J
    i = j
    j = i
}

gc and go/types both give an error.

gc:
prog.go:13: cannot use j (type J) as type I in assignment:
    J does not implement I (wrong type for f method)
        have f() J
        want f() I
prog.go:14: cannot use i (type I) as type J in assignment:
    I does not implement J (wrong type for f method)
        have f() I
        want f() J

go/types:
a.go:13:6: cannot assign j (variable of type J) to i (variable of type I)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions