Skip to content

cmd/compile: recursive anonymous interface defs compile but fail to run #10222

Closed
@ghost

Description

Should this program work?

package main

type T interface {
    m() interface {T}
}

type foo struct {
}

func (f *foo) m() interface {T} {
  return &foo{}
}

func main() {
    var t T
    t = &foo{}
    t.m()
}

It seems to compile but panics when run:
http://play.golang.org/p/swxTnFlwQI

By contrast this program works fine:

package main

type T interface {
    m() T
}

type foo struct {
}

func (f *foo) m() T {
    return &foo{}
}

func main() {
    var t T
    t = &foo{}
    t.m()
}

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

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions