]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: replace setDefType with pending type check
authorMark Freeman <mark@golang.org>
Mon, 24 Nov 2025 22:04:49 +0000 (17:04 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 27 Nov 2025 00:15:28 +0000 (16:15 -0800)
commit3531ac23d4aac6bdd914f14f65ee5fdc5e6e98fa
tree2e29591c6ee6b819f87e93f1986a4b491a3d8d84
parent2b8dbb35b0d6a5601ae9b6f1d1de106774251214
go/types, types2: replace setDefType with pending type check

Given a type definition of the form:

  type T RHS

The setDefType function would set T.fromRHS as soon as we knew its
top-level type. For instance, in:

  type S struct { ... }

S.fromRHS is set to a struct type before type-checking anything inside
the struct.

This permit access to the (incomplete) RHS type in a cyclic type
declaration. Accessing this information is fraught (as it's incomplete),
but was used for reporting certain types of cycles.

This CL replaces setDefType with a check that ensures no value of type
T is used before its RHS is set up.

This CL is strictly more complete than what setDefType achieved. For
instance, it enables correct reporting for the below cycles:

  type A [unsafe.Sizeof(A{})]int

  var v any = 42
  type B [v.(B)]int

  func f() C {
    return C{}
  }
  type C [unsafe.Sizeof(f())]int

Fixes #76383
Fixes #76384

Change-Id: I9dfab5b708013b418fa66e43362bb4d8483fedec
Reviewed-on: https://go-review.googlesource.com/c/go/+/724140
Auto-Submit: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
14 files changed:
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/typexpr.go
src/go/types/expr.go
src/go/types/typexpr.go
src/internal/types/errors/codes.go
src/internal/types/testdata/check/cycles0.go
src/internal/types/testdata/check/cycles2.go
src/internal/types/testdata/check/cycles4.go
src/internal/types/testdata/check/issues0.go
src/internal/types/testdata/fixedbugs/issue39634.go
src/internal/types/testdata/fixedbugs/issue49276.go
src/internal/types/testdata/fixedbugs/issue76383.go [new file with mode: 0644]
src/internal/types/testdata/fixedbugs/issue76384.go [new file with mode: 0644]
test/fixedbugs/issue18392.go