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

reflect: Implements fails with anonymous, recursive interfaces #56063

Open
mdempsky opened this issue Oct 5, 2022 · 1 comment
Open

reflect: Implements fails with anonymous, recursive interfaces #56063

mdempsky opened this issue Oct 5, 2022 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

mdempsky commented Oct 5, 2022

Program below should print and exit silently, but instead it reports an error.

The underlying issue here may be a cmd/compile issue though, since it works with go run -compiler=gccgo.

$ go run q.go
FAIL: "main.T".Implements("main.I") reports false

$ cat q.go
package main

import (
	"fmt"
	"reflect"
)

func main() {
	// statically verify that T implements I
	var _ I = T(0)

	i := reflect.TypeOf(new(I)).Elem()
	t := reflect.TypeOf(new(T)).Elem()
	if !t.Implements(i) {
		fmt.Printf("FAIL: %q.Implements(%q) reports false\n", t, i)
	}
}

type I interface{ m() interface{ I } }

type T int

func (T) m() interface{ I } { return nil }

/cc @golang/compiler

@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 5, 2022
@mdempsky mdempsky added this to the Unplanned milestone Oct 5, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 5, 2022
@mdempsky
Copy link
Member Author

mdempsky commented Oct 5, 2022

Probably the same underlying issue, but affecting type assertions:

$ go run q.go
main.T does not implement I

$ cat q.go
package main

import "fmt"

func main() {
	var i any
	i = T(0)

	if _, ok := i.(I); !ok {
		fmt.Printf("%T does not implement I\n", i)
	}
}

type I interface{ m() interface{ I } }

type T int

func (T) m() interface{ I } { return nil }

var _ I = T(0) // static assert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants