1 // expected: cannot convert value of type
2 //
3 // unsafe.Pointer is declared `__any->ptr`, so every operand type was accepted
4 // and a value that is not a pointer silently BECAME one. The spec allows a
5 // conversion to unsafe.Pointer from a pointer, a uintptr, unsafe.Pointer
6 // itself, or nil - and nothing else - which is what go/types enforces on the
7 // legacy side, so this is stage4 catching up rather than a new restriction.
8 //
9 // The hole was not theoretical: six sites in src/net passed a value that was
10 // not a pointer (rounds 43/84), the type checker handed the backend a value
11 // whose width it had guessed, and clang rejected the module with a type
12 // mismatch that named no source line. A struct value here is the smallest
13 // shape that used to compile.
14 package main
15 16 import (
17 "unsafe"
18 )
19 20 type box struct {
21 x int32
22 }
23 24 func main() {
25 var b box
26 p := unsafe.Pointer(b)
27 _ = p
28 println("unreachable")
29 }
30