Skip to content

go/types, types2: panic with cyclic generic type definition #75882

@griesemer

Description

@griesemer

Compiling

package p

type A[T B[T]] struct{}

type B[T A[T]] = A[T]

leads to a type checkere panic (after CL 711420).

testdata/manual.go:10:6  :  -- checking type A (white, objPath = )
testdata/manual.go:10:11 :  .  -- type B[T]
testdata/manual.go:10:10 :  .  .  -- instantiating type B with [T]
testdata/manual.go:10:10 :  .  .  .  -- type B
testdata/manual.go:12:6  :  .  .  .  .  -- checking type B (white, objPath = A)
testdata/manual.go:12:11 :  .  .  .  .  .  -- type A[T]
testdata/manual.go:12:10 :  .  .  .  .  .  .  -- instantiating type A with [T]
testdata/manual.go:12:10 :  .  .  .  .  .  .  .  -- type A
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  ## cycle detected: objPath = A->B->A (len = 2)
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  ## cycle contains: generic type in a type parameter list
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  => cycle is valid
testdata/manual.go:12:10 :  .  .  .  .  .  .  .  => A[T₁ invalid type] (under = <nil>) // *Named
testdata/manual.go:12:12 :  .  .  .  .  .  .  .  -- type T
testdata/manual.go:12:12 :  .  .  .  .  .  .  .  => T₂ (under = interface{}) // *TypeParam
testdata/manual.go:12:10 :  .  .  .  .  .  .  => A[T₂]
testdata/manual.go:12:11 :  .  .  .  .  .  => A[T₂] (under = <nil>) // *Named
testdata/manual.go:12:19 :  .  .  .  .  .  -- type A[T]
testdata/manual.go:12:18 :  .  .  .  .  .  .  -- instantiating type A with [T]
testdata/manual.go:12:18 :  .  .  .  .  .  .  .  -- type A
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  ## cycle detected: objPath = A->B->A (len = 2)
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  ## cycle contains: 0 values, 1 type definitions
testdata/manual.go:10:6  :  .  .  .  .  .  .  .  .  => cycle is valid
testdata/manual.go:12:18 :  .  .  .  .  .  .  .  => A[T₁ invalid type] (under = <nil>) // *Named
testdata/manual.go:12:20 :  .  .  .  .  .  .  .  -- type T
testdata/manual.go:12:10 :  .  .  .  .  .  .  .  -- Named.expandUnderlying A[T₂]
testdata/manual.go:12:10 :  .  .  .  .  .  .  .  => A[T₂] (tparams = [], under = <nil>)
testdata/manual.go:12:18 :  .  .  .  .  .  .  => <nil>
testdata/manual.go:12:19 :  .  .  .  .  .  => <nil> // <nil>
testdata/manual.go:12:6  :  .  .  .  .  => type B[T A[T]] = invalid type (black)
testdata/manual.go:10:10 :  .  .  .  => <nil> // <nil>
testdata/manual.go:10:10 :  .  .  => <nil>
testdata/manual.go:10:11 :  .  => <nil> // <nil>
The following panic happened checking types near:
        testdata/manual.go:12:6
        testdata/manual.go:10:6
--- FAIL: TestManual (0.07s)
panic: /Users/gri/goroot/src/cmd/compile/internal/types2/named.go:662: assertion failed [recovered, repanicked]
        panic: nil underlying [recovered, repanicked]

Metadata

Metadata

Labels

BugReportIssues describing a possible bug in the Go implementation.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions