Open findleyr opened 3 years ago
I don't believe this is a bug, and certainly not a release blocker. The spec says:
The functions Alignof and Sizeof take an expression x of any type and return the alignment or size, respectively, of a hypothetical variable v as if v was declared via var v = x.
The size of a variable of function type is independent of the function type and always the same, so arguably this is valid code.
The spec also doesn't explicitly disallow it.
[edited]
Interestingly, we do get a bug (initialization cycle) for this code:
package p
import "unsafe"
var f func([unsafe.Sizeof(f)]int)
which is not an initialization cycle (there is no initialization expression). Again, this shouldn't be a problem for the compiler/type-checker either. In any case, these are not release-blockers.
For reference, gccgo
accepts both these cases (possibly accidentally) without error and the function argument is [8]int
on a 64-bit platform.
Re-opening per edited comment above.
The following invalid cycle is currently detected by the compiler with the error "typechecking loop involving f".
https://play.golang.org/p/cfAFJHgsAkX
However no error is detected by go/types, both at master and in the
dev.typeparams
branch (where there have been some changes to cycle detection in function declarations).CC @griesemer