Unsafe functions such as `unsafe.Alignof`, `unsafe.Offsetof` and `unsafe.Sizeof` can be used for type declarations early on during compile, and as such, must be treated as builtins returning constants at compile time. It is still necessary to explicitely enable unsafe support in yaegi. The support of `unsafe.Add` has also been added. Fixes #1544.
19 lines
149 B
Go
19 lines
149 B
Go
package main
|
|
|
|
import "unsafe"
|
|
|
|
type T struct {
|
|
i uint64
|
|
}
|
|
|
|
var d T
|
|
|
|
var b [unsafe.Sizeof(d)]byte
|
|
|
|
func main() {
|
|
println(len(b))
|
|
}
|
|
|
|
// Output:
|
|
// 8
|