]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/types2: simplify under() and fix a crash
authorRobert Griesemer <gri@golang.org>
Sat, 13 Nov 2021 02:24:54 +0000 (18:24 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 13 Nov 2021 03:33:55 +0000 (03:33 +0000)
commitc2397905e027cdbab3a28d02813adcb82368422c
tree9a9da0dbc3b6afdb63337e6d3f6c8ccb35c13121
parentc54605266b746dd4d81e3753b55910e5c8dde5f0
cmd/compile/internal/types2: simplify under() and fix a crash

The simplified version of under exposed a bug (by crashing):
When a pointer base is used before the pointer is fully set
up, the base is nil. Set the pointer base to Typ[Invalid]
when creating the pointer, and add an extra safety check
into deref. Reviewed all code that creates pointers.

The same error cannot happen with other types because
accessing parts of another type results in an expression
that is not a type, and thus these kids of cycles cannot
happen.

Change-Id: I8332a281a534c094cfbb3623a636960865813ff6
Reviewed-on: https://go-review.googlesource.com/c/go/+/363665
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/lookup.go
src/cmd/compile/internal/types2/testdata/check/cycles.src
src/cmd/compile/internal/types2/type.go
src/cmd/compile/internal/types2/typexpr.go