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

cmd/compile: miscompilation of anonymous, recursive interfaces #56057

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

cmd/compile: miscompilation of anonymous, recursive interfaces #56057

mdempsky opened this issue Oct 5, 2022 · 1 comment
Assignees
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

The program below should run silently, but when compiled with cmd/compile it prints FAIL and different type signatures. It works correctly with gccgo.

$ cat z.go
package main

import "fmt"
import "reflect"

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

type J interface{ m() interface{ K } }
type K interface{ m() interface{ J } }

var i = reflect.TypeOf(new(interface{ I })).Elem()
var j = reflect.TypeOf(new(interface{ J })).Elem()
var k = reflect.TypeOf(new(interface{ K })).Elem()

func main() {
	if i != j || i != k || j != k {
		fmt.Println("FAIL")
		fmt.Println(i)
		fmt.Println(j)
		fmt.Println(k)
	}
}

$ go run z.go
FAIL
interface { main.m() interface { main.m@18 } }
interface { main.m() interface { main.m() interface { main.m@18 } } }
interface { main.m() interface { main.m() interface { main.m@18 } } }

The issue is that we're generating distinct link names for interface{ I } and interface{ J }, even though they denote identical types.

/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
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 5, 2022
@mknyszek mknyszek added this to the Go1.20 milestone Oct 12, 2022
@mdempsky mdempsky modified the milestones: Go1.20, Unplanned, Backlog Jan 10, 2023
@mdempsky
Copy link
Member Author

mdempsky commented Sep 6, 2023

Since Go 1.20, cmd/compile rejects this code with "invalid recursive type: anonymous interface refers to itself".

@mdempsky mdempsky closed this as completed Sep 6, 2023
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

3 participants