mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: reject not-in-heap types as type arguments
After running the types2 type checker, walk info.Instances to reject any not-in-heap type arguments. This is feasible to check using the types2 API now, thanks to #46731. Fixes #54765. Change-Id: Idd2acc124d102d5a76f128f13c21a6e593b6790b Reviewed-on: https://go-review.googlesource.com/c/go/+/427235 Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
e4b624eae5
commit
ca634fa2c5
3 changed files with 79 additions and 0 deletions
|
|
@ -256,3 +256,28 @@ func isTypeParam(t types2.Type) bool {
|
|||
_, ok := t.(*types2.TypeParam)
|
||||
return ok
|
||||
}
|
||||
|
||||
// isNotInHeap reports whether typ is or contains an element of type
|
||||
// runtime/internal/sys.NotInHeap.
|
||||
func isNotInHeap(typ types2.Type) bool {
|
||||
if named, ok := typ.(*types2.Named); ok {
|
||||
if obj := named.Obj(); obj.Name() == "nih" && obj.Pkg().Path() == "runtime/internal/sys" {
|
||||
return true
|
||||
}
|
||||
typ = named.Underlying()
|
||||
}
|
||||
|
||||
switch typ := typ.(type) {
|
||||
case *types2.Array:
|
||||
return isNotInHeap(typ.Elem())
|
||||
case *types2.Struct:
|
||||
for i := 0; i < typ.NumFields(); i++ {
|
||||
if isNotInHeap(typ.Field(i).Type()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue