interp: improve support of unsafe

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.
This commit is contained in:
Marc Vertes
2023-04-26 10:16:05 +02:00
committed by GitHub
parent d6ad13acea
commit dc7c64ba88
10 changed files with 131 additions and 58 deletions

17
_test/unsafe10.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import "unsafe"
type T struct {
X uint64
Y uint64
}
func f(off uintptr) { println(off) }
func main() {
f(unsafe.Offsetof(T{}.Y))
}
// Output:
// 8