Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ipfreely/.cache/go-build'
GOENV='/home/ipfreely/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ipfreely/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ipfreely/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go1.22.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go1.22.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ipfreely/projects/gobug/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3230307039=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Experimenting with limits of the generic type system. Error triggered by addition of Blocks() to Range interface.

// go.mod
module example.com/bug/v2

go 1.22.1
// bug.go
package gobug

type Iterator[A any] func() (bool, A)

type Set[A any] interface {
    Addresses() Iterator[A]
    Ranges() Iterator[Range[A]]
}

type Range[A any] interface {
    Set[A]
    // Problem line
    Blocks() Iterator[Block[A]]
}

type Block[A any] interface {
    Range[A]
}

type rangeImpl[A any] struct{}

func (r *rangeImpl[A]) Addresses() Iterator[A] {
    return func() (bool, A) {
        var a A
        return false, a
    }
}

func (r *rangeImpl[A]) Ranges() Iterator[Range[A]] {
    return func() (bool, Range[A]) {
        var a Range[A]
        return false, a
    }
}

func (r *rangeImpl[A]) Blocks() Iterator[Block[A]] {
    return func() (bool, Block[A]) {
        var a Block[A]
        return false, a
    }
}

func NewRange[A any]() Range[A] {
    return &rangeImpl[A]{}
}
// bug_test.go
package gobug_test

import (
    "testing"

    gobug "example.com/bug/v2"
)

func TestNetRange(t *testing.T) {
    type AddrImpl struct{}
    r := gobug.NewRange[AddrImpl]()
    if r == nil {
        t.Fail()
    }
}

What did you see happen?

Internal compile error running go test

$ go test example.com/bug/v2
# example.com/bug/v2_test [example.com/bug/v2.test]
./bug_test.go:11:31: internal compiler error: gobug.NewRange[go.shape.struct {}](&gobug..dict.NewRange[example.com/bug/v2_test.AddrImpl·1]) (type gobug.Range[go.shape.struct {}]) is not shape-identical to gobug.Range[example.com/bug/v2_test.AddrImpl·1]

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
FAIL    example.com/bug/v2 [build failed]
FAIL

What did you expect to see?

Expected code to compile or compiler to emit error saying what is illegal about the code.

Comment From: ALTree

Reproducible on tip too.

Comment From: cuonglm

Simpler reproducer:

package p

type Iterator[A any] func() (bool, A)

type Range[A any] interface {
    Blocks() Iterator[Block[A]]
}

type Block[A any] interface {
    Range[A]
}

type rangeImpl[A any] struct{}

func (r *rangeImpl[A]) Blocks() Iterator[Block[A]] {
    return func() (bool, Block[A]) {
        var a Block[A]
        return false, a
    }
}

func NewRange[A any]() Range[A] {
    return &rangeImpl[A]{}
}

type AddrImpl struct{}

var _ = NewRange[AddrImpl]()

I think this has the same underlying problem with #65362, https://go-review.googlesource.com/c/go/+/559656 would fix this.

Comment From: gopherbot

Change https://go.dev/cl/559656 mentions this issue: cmd/compile: fix recursive generic interface instantiation